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

The Coin is not respawning after 5 seconds?

Asked by 5 years ago
Edited 5 years ago
local db = true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            script.Parent.Transparency = 1
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
            script.Sound:Play()
            script.Parent.Transparency = 1
            wait(5)
            db = true
            script.Parent.Transparency = 0
        end
    end
end)

1 answer

Log in to vote
0
Answered by
blockmask 374 Moderation Voter
5 years ago

I tested this out myself, and it works. Also, I fixed parts in your script

local db = true
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db then
            db = false
            script.Parent.Transparency = 1
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if player then
                player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
                script.Sound:Play()
                script.Parent.Transparency = 1
                wait(5)
                script.Parent.Transparency = 0
                db = true
            end
        end
    end
end)

seemed like the rest of the script was running even though it didn't check to see if it was an actual player, and maybe make this a server script, and check to see if the script isn't disabled

Ad

Answer this question