Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

The Coin is not respawning after 5 seconds?

Asked by 1 year ago
Edited 1 year 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 371 Moderation Voter
1 year 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