Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make a ship spawner that will take away Coins when clicked?

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)

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.