How to teleport the player on spawn

I am making an obby, and I have a checkpoint system set up that uses the leaderboard to store the stage for each player. I have a bunch of platforms in the checkpoints folder that update the leaderboard stat on touch, and that works fine. The problem I’m having is I can’t seem to teleport the character once it spawns in, it always spawns on the first platform (the one with the actual spawn point)
This is my respawn script. It’s a normal script inside the starter character scripts folder. I had it print out the position variable right before teleporting, and that worked fine. I’ve tried a bunch of different ways to teleport, but none of the work.

local players = game.Players
local character = script.Parent
local player = players:GetPlayerFromCharacter(character)
local checkpoints = workspace.Platforms.Checkpoints

local stage = player.leaderstats:WaitForChild("Stage").Value
local checkpoint = checkpoints:FindFirstChild(tostring(stage))
local pos = checkpoint.CFrame.Position
character.HumanoidRootPart.CFrame.Position = Vector3.new(pos.X, pos.Y+10, pos.Z)
7 Likes

Ah i also did an Obby and noticed that when i was moving the player to latest checkpoint after respawn on a local script it was sometimes not porting the player. Instead on the local script i send an event to the server “CharRespawned” and do the same code on the server and it works perfectly

4 Likes

The script isn’t a local script, it’s just a normal script. I thought that meant it was server-side…

2 Likes

I just tried it, and now it says “attempt to index nil with ‘leaderstats’”.
Here’s the local script in the starter character scripts:

game.ReplicatedStorage.Respawn:FireServer(script.Parent)

and here’s the server script:

local checkpoints = workspace.Platforms.Checkpoints

game.ReplicatedStorage.Respawn.OnServerEvent:Connect(function(character)
	local player = game.Players:GetPlayerFromCharacter(character)
	local stage = player.leaderstats:WaitForChild("Stage").Value
	local checkpoint = checkpoints:FindFirstChild(tostring(stage))
	local pos = checkpoint.CFrame.Position
	character.HumanoidRootPart.CFrame = CFrame.new(pos.X, pos.Y+10, pos.Z)
end)
1 Like

I don’t believe there is a normal script, but the item that just says “script” on Roblox studio is always server-side

local players = game.Players
local character = script.Parent
local player = players:GetPlayerFromCharacter(character)
local checkpoints = workspace.Platforms.Checkpoints

local stage = player.leaderstats:WaitForChild("Stage").Value
local checkpoint = checkpoints:FindFirstChild(tostring(stage))

clonedTree:MoveTo(Vector3.new(checkpoint.Position.X, checkpoint.Position.Y + 10,  checkpoint.Position.Z))

This should work

1 Like

What’s the “clonedTree” part? Is that supposed to be the character?
I tried it that way and it didn’t work. No errors in the console, it just didn’t teleport me.

Would a Spawn Location work?

1 Like

In the past I have used spawn locations and teams, but I really don’t want to do that again.

1 Like

May I ask why to further be able to help?

I prefer the leaderboard to the teams, because I feel it looks nicer on the player list. It’s also a lot easier to add a new checkpoint: I just have to copy an existing one, change the location, and change the name. For the teams, I have to copy it, change the team color, and make a whole new team for it.

1 Like

Oh I think I can help. is this for an obby?

Yes. It’s a speedrun obby.
(Character Limit)

Well I highly recommend Shnerpy’s Obby Kit: https://create.roblox.com/marketplace/asset/5711013812/Shnerpys-Obby-Kit

It uses the leaderboard (leaderstat) system to save stages and its very customizable

Hope this helped!

1 Like

I’ll try it. Thanks for your help!

2 Likes

heyo!

you cannot interfere with the characters CFrame when it is initially spawned, because the character has not yet had the chance to apply it’s normal properties.

to counter this problem add a game:GetService("RunService").Stepped:Wait() before doing so.

1 Like

Oh sorry that was from my other game lol, hopefully this works

local players = game.Players
local character = script.Parent
local player = players:GetPlayerFromCharacter(character)
local checkpoints = workspace.Platforms.Checkpoints

local stage = player.leaderstats:WaitForChild("Stage").Value
local checkpoint = checkpoints:FindFirstChild(tostring(stage))

character:MoveTo(Vector3.new(checkpoint.Position.X, checkpoint.Position.Y + 10,  checkpoint.Position.Z))

This should work

1 Like

Thanks everyone! I did what you said and it works now! Here’s the completed script:

local players = game.Players
local character = script.Parent
local player = players:GetPlayerFromCharacter(character)
local checkpoints = workspace.Platforms.Checkpoints

local stage = player.leaderstats:WaitForChild("Stage").Value
local checkpoint = checkpoints:FindFirstChild(tostring(stage))

game:GetService("RunService").Stepped:Wait()

character:MoveTo(Vector3.new(checkpoint.Position.X, checkpoint.Position.Y + 10,  checkpoint.Position.Z))
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.