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