CCCPaste

Stock and Give Item (Script)

local ServerStorage = game:GetService("ServerStorage")

local StockLabel = script.Parent.StockGui.stockLabel
local Stock = 10
local Cash = 25

local function GiveFood(player)

	if Stock >= 1 then
		local ClonedFood = ServerStorage.ItemsFolder.WaterBottle:Clone()
		ClonedFood.Parent = player.Backpack
		Stock -= 1
	elseif Stock <= 0 then
		script.Parent.ClickDetector.MaxActivationDistance = 0
		for i = 10,0,-1 do
			StockLabel.Text = "STOCK IN"..i.." SECONDS" 
			wait(1)
		end
		StockLabel.Text = "WATERBOTTLES STOCK: "..Stock --- Change ItemName
		Stock += Stock
	end
end

script.Parent.ClickDetector.MouseHoverEnter:Connect(function()
	if not script.Parent:FindFirstChild("SelectionBox") then
		local SelectionBox = Instance.new("SelectionBox")
		SelectionBox.Adornee = script.Parent
		SelectionBox.Parent = script.Parent
		SelectionBox.Color3 = Color3.new(1, 1, 1)
		SelectionBox.Transparency = 0.8
	end
end)

script.Parent.ClickDetector.MouseHoverLeave:Connect(function()
	if script.Parent:FindFirstChild("SelectionBox") then
		script.Parent.SelectionBox:Destroy()
	end
end)

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	StockLabel.Text = "WATERBOTTLES STOCK: "..Stock --- Change ItemName
	if player.Coins.Value >= Cash then
		player.Coins.Value = player.Coins.Value - Cash
		GiveFood(player)
	end
end)