Why does the player not teleport to their level?

Hi! I’m creating a roblox speed run / obby game with multiple levels. I’m avoiding using teams as stages/levels because I think it floods the player leaderboard unnecessarily. So I’ve made it so that when the player was to ever respawn they would instantly be teleported to their stage checkpoint.

However, the problem is that there are a few instances where this doesn’t work. I would say it works 70% of the time, so when the player respawns they’re back at level 1 when in actuality they should spawn at a higher. I’ve tried print debugging it, but I couldn’t find much reason why it sometimes doesn’t work.

Here’s the code:

game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	local Stage = Instance.new("IntValue")
	Stage.Name = 'Stage'
	Stage.Value = 1
	Stage.Parent = leaderstats
		
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		wait()
		if Stage.Value > 1 and Player.Team ~= game.Teams.Winners then
			wait(0.3)
			--Character.HumanoidRootPart.CFrame = workspace.Stages[Stage.Value].StarBrick.CFrame
			Character:MoveTo(workspace.Stages[Stage.Value].StarBrick.Position)
			print(Player.Name,'shouldve TPd', Stage.Value,' to ',workspace.Stages[Stage.Value].Name)
		else
			print('didnt TP')
		end
	end)
end)

Any help would be appreciated! Thanks!

2 Likes

is there any errors? with the script

1 Like
game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	local Stage = Instance.new("IntValue")
	Stage.Name = 'Stage'
	Stage.Value = 1
	Stage.Parent = leaderstats
		
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		wait()
		if Stage.Value > 1 and Player.Team ~= game.Teams.Winners and workspace.Stages:FindFirstChild(Stage.Value) ~= nil then
			wait(0.3)
			Character.HumanoidRootPart.Position = workspace.Stages[Stage.Value].StarBrick.Position
			--Character:MoveTo(workspace.Stages[Stage.Value].StarBrick.Position)
			print(Player.Name,'shouldve TPd', Stage.Value,' to ',workspace.Stages[Stage.Value].Name)
		else
			print('didnt TP')
		end
	end)
end)
2 Likes

No errors. For instance, if the player were to die at level 10 and spawn at level 1. The script would still output “Player shouldve TPd 10 to 10.”

Thanks. I’ll try this out and tell you how it goes.

change MoveTo to PivotTo and use a CFrame instead of a Position

1 Like

setting the position of the humanoid root part is not recommended and usually breaks stuff
you want to move the entire character model with :PivotTo

Thanks for the help, but sometimes the script still fails to teleport the player to their stage.

Thanks for the input but unfortunately the problem still remains. I’m not sure if it’s an issue with teleportation, or the character isn’t loading in fast enough(?), or else

is it a local script or a server script and if so where is it

It was originally a server script in ServerScriptService, but I decided to move the Player.CharacterAdded section to a new local script, to StarterCharacterScripts which made it work 100% of the time, which honestly I should’ve done a lot earlier. So I managed to solve my own issue. I do appreciate the help though, not many people come back to old posts like this.

Thanks!

ah yes nice im trying to make a simular script so that whe the gui button is pressed they get teleported to their current stage, i was wondering if you could give me advise and np btw

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