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 6 years ago
Edited 6 years ago
01local db = true
02script.Parent.Touched:Connect(function(hit)
03    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
04        if db == true then
05            db = false
06            script.Parent.Transparency = 1
07            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
08            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
09            script.Sound:Play()
10            script.Parent.Transparency = 1
11            wait(5)
12            db = true
13            script.Parent.Transparency = 0
14        end
15    end
16end)

1 answer

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

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

01local db = true
02script.Parent.Touched:Connect(function(hit)
03    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
04        if db then
05            db = false
06            script.Parent.Transparency = 1
07            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
08            if player then
09                player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
10                script.Sound:Play()
11                script.Parent.Transparency = 1
12                wait(5)
13                script.Parent.Transparency = 0
14                db = true
15            end
16        end
17    end
18end)

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