I'm trying to make a working checkpoint that doesn't use teams, and displays leaderstats instead of showing you in a team. I wanna do that so the leaderboard of players in the top right hand corner doesn't look too messy. And for some reason, when I reset to test if the checkpoint works, I am greeted with this error: "Grassy2Spawn.Checkpoint:9: attempt to index nil with 'leaderstats'", and I don't understand it. It used to not give me that error and not work at all, it just wouldnt work. I made the wait 2 seconds longer, then the error popped up. Can somebody help?
EDIT: I forgot to put the if statement in a while loop, if thats the reason why, I'm stupid.
EDIT 2: I edited the code on this question to have the while loop.
EDIT 3: The question is still not solved
local Checkpoint = script.Parent
local BackTo = Checkpoint.BackTo
Checkpoint.Touched:Connect(function(hit)
local Character = hit.Parent
local Root = Character:FindFirstChild("HumanoidRootPart")
local Player = game.Players:GetPlayerFromCharacter(Character)
Player.leaderstats.Stage.Value = 2
while true do
if Character.Humanoid.Health == 0 then
wait(10)
Root.CFrame = CFrame.new(BackTo.Position)
end
wait(1)
end
end)

1 comment
wow this has a lot of views.