Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to fix this regeneration coin glitch?

Asked by 6 years ago

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

Log in to vote
0
Answered by
Sorukan 240 Moderation Voter
6 years ago
Edited 6 years ago

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.

Ad

Answer this question