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