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)
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
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)
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))
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.
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.
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.
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))
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))