Hello!
I am making an obby that will save your progress when you leave the game. Your current stage will be shown through leaderstats, not teams. I want the player to spawn in on the correct spawn when they join the game, how would I do this?
You can detect if the Player’s Stage has changed by using the Changed
Event for Value Objects & use the
CharacterAdded
event for every time a Character Model gets added into the workspace
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local leaderstats = Player:WaitForChild("leaderstats")
local Stage = leaderstats:WaitForChild("Stage")
local HRP = Character:WaitForChild("HumanoidRootPart")
Stage.Changed:Connect(function()
if Stage.Value == 1 then
HTP.Position = workspace.Stage1.Position
elseif Stage.Value == 2 then
HTP.Position = workspace.Stage2.Position
end
end)
end)
end)
That’s going to be very long if there are more than 2 stages, a better way to do this would be to put the checkpoints in a folder with the name of the checkpoint being the stage number it is and doing this
local checkpoints = workspace.Checkpoints:GetChildren()
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local leaderstats = Player:WaitForChild("leaderstats")
local Stage = leaderstats:WaitForChild("Stage")
local HRP = Character:WaitForChild("HumanoidRootPart")
Stage.Changed:Connect(function(val)
HRP.Position = checkpoints[tostring(val)].Position + Vector3.new(0,3.25,0)
end)
end)
end)
Edit, I think I forgot to make val to a string, if it caues issues, try it out by converting to a string and then getting the checkpoint
You can seriously do that? Ok tables are gonna confuse me even more I’ve only been known to do it like that but that saves so much more time w o w
Haha it’s okay! We learn new things al lthe time!
So, do you need to change the value of the stage leaderstats to the number of the stage, and this will essentially just make you spawn at the part equal to your leaderstats value, right?
Just wanna make sure I read this right.
Don’t you also need to change the leaderstats when you touch the part, so that it can detect?