So, I have this script and what I want it to do is when the player touches a brick, it sets their money to 0.
However, it only works half the time (So another script respawns is every 300 seconds).
Is there an easy way to do this?
function onTouched(hit) local b = game.Players:GetPlayerFromCharacter(hit.Parent) if b.leaderstats:findFirstChild("Jump Distance").Value >= 1 then b.leaderstats:findFirstChild("Jump Distance").Value = 0 end end script.Parent.Touched:connect(onTouched)
Give this a shot, it should work.
script.Parent.Touched:connect(function(Touched) -- Anonymous function. if game.Players:FindFirstChild(Touched.Parent.Name) ~= nil then local Plr = game.Players[Touched.Parent.Name] if Plr.leaderstats ~= nil then if Plr.leaderstats['Jump Distance'].Value >= 1 then Plr.leaderstats['Jump Distance'].Value = 0 end end end end)
script.Parent.Touched:connect(function(Part) if Part.Parent:FindFirstChild("Humanoid") ~= nil then local b = game.Players:GetPlayerFromCharacter(Part.Parent) if b:WaitForChild("leaderstats"):FindFirstChild("Jump Distance").Value >= 1 then b.leaderstats:FindFirstChild("Jump Distance").Value = 0 end end end)
This should work. If not, message me ;)