I am trying to make a ship spawner but I want it to take away Coins when clicked here is my script:
~~~~~~~~~~~~~~~~~
local Coins = game.Players:WaitForChild("leaderstats.Coins")
local ServerStorage = game:GetService("ServerStorage")
local detector = workspace["Regen Speedboat 50 Coins"] local debounce = false script.Parent.ClickDetector.MouseClick:Connect(function() if debounce then return end debounce = true print("I was clicked!") local Copy = ServerStorage:FindFirstChild("SpeedBoat"):Clone() Copy.Parent = workspace Copy.Name = "Speedone" Copy:MoveTo(Vector3.new(-14, 2.5, -344)) wait(6) debounce = false end)
~~~~~~~~~~~~~~~~~
This should work. If this does please accept my answer as the solution :)
local ServerStorage = game:GetService("ServerStorage") local detector = workspace["Regen Speedboat 50 Coins"] local debounce = false local SHIP_COST = 50--Coins cost script.Parent.ClickDetector.MouseClick:Connect(function(player) if debounce then return end debounce = true print("I was clicked!") local coins = player.leaderstats.Coins if coins.Value >= SHIP_COST then coins.Value -= SHIP_COST local Copy = ServerStorage:FindFirstChild("SpeedBoat"):Clone() Copy.Parent = workspace Copy.Name = "Speedone" Copy:MoveTo(Vector3.new(-14, 2.5, -344)) end wait(6) debounce = false end)