CCCPaste

Food Stock 3

local CashGui = script.Parent.CashGui

local Number = 100
local MaxNumber = 30

CashGui.CashFrame.stockLabel.Text = "STOCK: "..MaxNumber

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	
	if not player.Backpack:FindFirstChild("Cookie") then
		if player.Coins.Value >= Number then
			player.Coins.Value = player.Coins.Value - Number

			game.ServerStorage.Foods.Cookie:Clone().Parent = player.Backpack
			MaxNumber = MaxNumber - 1

			CashGui.CashFrame.stockLabel.Text = "STOCK: "..MaxNumber
		end
	else
		if player.Coins.Value >= Number then
			player.Coins.Value = player.Coins.Value - Number

			player.Backpack:FindFirstChild("Cookie").stacks.Value += 1
			MaxNumber = MaxNumber - 1

			CashGui.CashFrame.stockLabel.Text = "STOCK: "..MaxNumber
		end
	end
	
	while wait() do
		if MaxNumber == 0 then
			script.Parent.ClickDetector.MaxActivationDistance = 0
			CashGui.CashFrame.stockLabel.Text = "STOCK: "..MaxNumber
			wait(1)
			break
		end
	end
	
end)



script.Parent.ClickDetector.MouseHoverEnter:Connect(function()
	script.Parent.SelectionBox.Visible = true
	CashGui.Enabled = true
end)

script.Parent.ClickDetector.MouseHoverLeave:Connect(function()
	script.Parent.SelectionBox.Visible = false
	CashGui.Enabled = false
end)