Basically, i’m making a obby game for a bit of fun because i was bored and while coding it, it worked fine in my powerfull work computer but when going to my low performance laptop to work on it i found an issue when player joins they aren’t teleport to they spots.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local userstage = workspace.Checkpoints:FindFirstChild(tostring(player.leaderstats.Stage.Value))
if userstage then
if userstage:IsA("Model") then
character.HumanoidRootPart.CFrame = userstage.PrimaryPart.CFrame + Vector3.new(0, 5, 0)
else
character.HumanoidRootPart.CFrame = userstage.CFrame + Vector3.new(0,5,0)
end
end
-- Detect when a player die
character.Humanoid.Died:Connect(function()
-- Wait for the player to respawn
player.CharacterAdded:Wait()
end)
end)
end)
Is there a easy way i can fix the following issue?
If the user isn’t being teleported to their spot then “userstage” is returning nil, which might be because you’re immediately checking wether it exists or not.
Try doing this instead:
if not userstage then
repeat task.wait() until userstage
end
if userstage:IsA("Model") then
character.HumanoidRootPart.CFrame = userstage.PrimaryPart.CFrame + Vector3.new(0, 5, 0)
else
character.HumanoidRootPart.CFrame = userstage.CFrame + Vector3.new(0,5,0)
end
(Delete your if statement and replace it with this block of code)
Oh yeah, you should probably also change the
to:
character = player.Character or player.CharacterAdded:Wait()