hi, im making an RPG based game. i have the leaderboard value of "lives" that tells the player how many lives they have. im trying to work out a script so that once the value of "Lives" reaches 0, it'll teleport the player to another area. heres what i got so far
local p = game.Players:GetChildren()
local stats = p:findFirstChild("leaderstats")
local sp = stats:findFirstChild("Lives")
if sp == nil then return false end
if (sp.Value == 0) then
for i = 1, #p do
p[i].Character:MoveTo(Vector3.new(-37206.949, 516.942, -9.089))
end
end
this obviously doesnt work, but im trying to figure out how i should write to so that it'll teleport the players based on the Lives value. im also getting an error on line 2 for " attempt to call a nil value". what should i do?

1 comment
this worked perfectly! only issue is after the player has died at "0" they get teleported to the right place, but will respawn and stay in the original area