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

Can seem to make a script wait before doing it again and destroy it?

Hi i have my Cash Giving script, I tried to make it so it get destroyed when touched and can't seem to remove the model.Plus it just give money but spam it, I can't figure out why!

function onTouched(hit)
if hit.Parent.Humanoid~= nil then
local cash = game.Players:findFirstChild(hit.Parent.Name).leaderstats.Cash
wait(1)
cash.Value = cash.Value + 1
script.Parent:Destroy()
wait(5)
end
script.Parent.Touched:connect(onTouched)

1 answer

We need to set up a variable so that the function will only run once

local ran=false
function onTouched(hit)
if ran==false and hit.Parent.Humanoid~= nil then ran=true
local cash = game.Players:findFirstChild(hit.Parent.Name).leaderstats.Cash
wait(1)
cash.Value = cash.Value + 1
script.Parent:Destroy()
wait(5)
end
script.Parent.Touched:connect(onTouched)

1 comment

0

Does not seem to work..

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