I want to teleport a player once they have respawned or change their respawn point. i was thinking something like this maybe would work but it didn't:
local checkfolder = game.Workspace.checkpoints
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Checkpoint = Instance.new("IntValue",leaderstats)
Checkpoint.Name = "Stage"
for i,v in pairs(checkfolder:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
local char = hit.Parent
local plr = Players:GetPlayerFromCharacter(char)
if i == 1 then
Checkpoint.Value = 2
if plr then
plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart").CFrame = v.CFrame * CFrame.new(0, 3, 0)
end
end
if i == 2 then
Checkpoint.Value = 3
end
if i ==3 then
Checkpoint.Value = 4
end
if i == 4 then
Checkpoint.Value = 5
end
if i == 5 then
Checkpoint.Value = 6
end
if i == 6 then
Checkpoint.Value = 7
end
if i == 7 then
Checkpoint.Value = 8
end
if i == 8 then
Checkpoint.Value = 9
end
end)
end
end
end)
it didn't work, so i set respawn time to 0 and removed the code
repeat wait() until humanoid.Health == 100
but it still didn't work
Edit: I posted the full script so you can find out what the problem is. The output isn't processing any errors.
Checkpoint.Value will equal 1 when it steps on the spawn and that is another script.
This is the other script:
game.Players.PlayerAdded:Connect(function(plr)
local Checkpoint = plr.leaderstats.Stage
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("SpawnLocation") then
v.Touched:Connect(function(char)
if char.Parent:FindFirstChild("Humanoid") then
Checkpoint.Value = 1
end
end)
end
end
end)
So i am unable to wait when character is added otherwise the checkpoint value will equal to 0

9 comments
There is a event of Player call CharacterAdded, the event will fire when the player spawn or respawn https://developer.roblox.com/api-reference/event/Player/CharacterAdded
You can wait the player respawn by simply type this: plr.CharacterAdded:Wait() * :Wait() is different from Wait(), we use :Wait() to make the script wait until a event fire.
I've already tried this, but it doesn't work
the "plr" is either the left leg or the right leg
Wait does it throw any error?
no
And what happen when the script run?
The leaderstats works except the checkpoint value stays 0 when i join. Also when i die, I spawn at the start. I'm sorry for bothering you, i'm just not experienced and i'm only 13 years old
I think this post will help you make a checkpoint system https://education.roblox.com/en-us/resources/intro-to-studio-checkpoints and I'm 13 too :D