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

The Coin is not respawning after 5 seconds?

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

✓ Accepted answer

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

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