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

Buggy Leaderboard Reset Script. Anyone got a better way?

Asked by 9 years ago

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?

  • Michael
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)
0
Touched tends to do weird things. It works best if the part's CanCollide property is set to false. Try setting it to false, and see how it works. Discern 1007 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

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)

Ad
Log in to vote
0
Answered by 9 years ago
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 ;)

Answer this question