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
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.