I’m trying to make a quick little teleport feature (I don’t really care how bad it is). But for some reason when I play the game the output says that my “player” doesn’t have leaderstats in it (which it does btw).
game.Players.PlayerAdded:Connect(function(plr)
if plr.leaderstats.Level.Value == 1 then
plr.Character.HumanoidRootPart.CFrame = workspace.A.CFrame
else
if plr.leaderstats.Level.Value == 2 then
plr.Character.HumanoidRootPart.CFrame = workspace.B.CFrame
end
end
end)
You can add WaitForChild, to check if leader stats and level actually exist as the player child at that moment.
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local Level = leaderstats:WaitForChild("Level")
if Level Value == 1 then
plr.Character.HumanoidRootPart.CFrame = workspace.A.CFrame
else
if Level.Value == 2 then
plr.Character.HumanoidRootPart.CFrame = workspace.B.CFrame
end
end
end)
It could be because the script runs slightly before leaderstats is created. I would instead create the leaderstats in the same script above the playeradded part
Maybe try using WaitForChild on the HumanoidRootPart? Plus, The CharacterAdded event will fire everytime the Character gets added, So it has less chances of the Code not working due to the fact referencing the Character before it gets added may result in an error.