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

Buggy Leaderboard Reset Script. Anyone got a better way?

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)

1 comment

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.

2 answers

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

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