Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by
MemezyDev 172
2 years ago
Edited 2 years ago

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)
Ad

Answer this question