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

Why is my leaderboard script not working? [UNSOLVED]

Asked by 9 years ago

I have a script in a tool that every time the tool is equipped and the holder of the tool clicks it adds points to the leaderboard. I have a script creating the Leaderboards, that works. But when I click with the tool out, only the first part of the script runs. So the Sandwich gets stuck in my mouth and never moves... The output says:

21:13:18.655 - Players.Player1.Backpack.Tool.SandwichScript:23: attempt to index a nil value 21:13:18.655 - Stack Begin 21:13:18.656 - Script 'Players.Player1.Backpack.Tool.SandwichScript', Line 23 21:13:18.656 - Stack End 21:13:18.656 - Disconnected event because of exception

Here is the script or "SandwichScript" (Yes it is an edited Sandwich gear):

 wait(.5)
local Tool = script.Parent;

enabled = true




function onActivated()
if not enabled then
return
end

enabled = false
Tool.GripForward = Vector3.new(-0.97, 1.02e-005, -0.243)
Tool.GripPos = Vector3.new(-0.2, 0, -1.23)
Tool.GripRight = Vector3.new(0.197, 0.581, -0.79)
Tool.GripUp = Vector3.new(-0.141, 0.814, 0.563)

local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent) 

if player then
player.leaderstats:findFirstChild("Taco Bites").Value = player.leaderstats:findFirstChild("Taco Bites").Value + 1
wait(.4)
end
Tool.Handle.EatSound:Play()

wait(.8)

local h = Tool.Parent:FindFirstChild("Humanoid")
if (h ~= nil) then
if (h.MaxHealth > h.Health + 1.6) then
h.Health = h.Health + 1.6
else    
h.Health = h.MaxHealth
end
end

Tool.GripForward = Vector3.new(-1, 0, -0)
Tool.GripPos = Vector3.new(0.2, 0, 0)
Tool.GripRight = Vector3.new(0,0, -1)
Tool.GripUp = Vector3.new(0,1,0)


enabled = true

end

function onEquipped()
Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

Thank you for reading! -Leg0Brick

Answer this question