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

Is there a way to fix this regeneration coin glitch?

I made this coin, where when you collect it, it disappears, and currency is added to your leaderstats. But the coin keeps respawning every 5 seconds, even if it is not collected. How do I make it so that it only respawns if someone collected it?

model = game.Workspace.Coin 

backup = model:clone()

while true do
	wait(5) 

	model:remove()
	model = backup:clone()
	model.Parent = game.Workspace
	model:makeJoints()

end


1 answer

You can do that with a Touched event which checks whether or not a player has touched the coin before proceeding to remove it. Your while loop will just keep repeating the process of removing and cloning the coin regardless whether someone picked it up or not.

local model = game.Workspace.Coin 

local backup = model:Clone()

model.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then -- if the part that touched it has a humanoid then
	    model:remove()
	    wait(5)
  	    model = backup:clone()
   	    model.Parent = game.Workspace
   	    model:makeJoints()
	end
end)

Don't forget to insert this script inside the original Coin also, i personally haven't tested this out yet but it should work.

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