I am trying to make a coin system in my game. It's working except that I just want the coins to respawn. What can I add to this script to make the coins respawn after a certain time limit?

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 + 10
			script.Sound:Play()
		end
	end	
end)

4 comments

0

connect is deprecated use Connect

0

It was working fine until I used Connect. The character touches it and it disappears & receives no points.

0

Changing connect to Connect will not negatively affect your script in any way. Also, changing the transparency to 1 is not the best way to go about this. Changing the transparency will only make the coin invisible, meaning if the player touches it, they will still receive points. You can instead change the coin's parent to nil and set it back to whatever it was parented to to begin with after

0

the amount of time you'd like the coin to regenerate.