I put this script in the checkpoint parts
local Part = script.Parent
local checkpoints = script.Parent.Parent
Part.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[plr.leaderstats.Stage.Value ].CFrame
char.Humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(plr.leaderstats.Stage.Value )) or touch.Name == "End" then
plr.leaderstats.Stage.Value = touch.Name
end
end
end)
end)
but the player does not spawn there when they join or die. I still have a server script service script which does this
wait(5)
local dss = game:GetService("DataStoreService")
print ("Checkpoints leaderstats working")
local checkpoints = workspace.Checkpoints
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")
hrp:GetPropertyChangedSignal("CFrame"):Wait()
hrp.CFrame = checkpoints[plr.leaderstats.Stage.Value ].CFrame
end)
end)
You’re never actually setting the spawn point of the player. You’re not even checking when the player is dead.
1 Like
How do i set the spawn and check if they die. A code sample would be helpful
Well I can’t really write you the code for it but in my opinion you don’t even need to write code for this. Just use the native SpawnLocations and set them to autochange team on touch. Then just save the player’s team color.
1 Like
I used to do that but I do not want to use teams as that limits the number of levels
Then just manually change the respawn location and save that. Use Roblox’s tutorial for it.
1 Like
If I’ve solved your problem make sure to mark my post as a solution. If not please do ask further questions!
I am trying to make a checkpoint system which has no teams, does not let the player skip or go back, spawns the player at the checkpoint on join and death and doesn’t spawn at the start sometimes.
What I have so far:
wait(5)
local dss = game:GetService("DataStoreService")
local Datastore = dss:GetDataStore("ObbyData")
local checkpoints = workspace.Checkpoints
print("Checkpoints leaderstats working")
game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[plr.leaderstats.Stage.Value].CFrame
char.Humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(plr.leaderstats.Stage.Value))or touch.Name == "End" then
plr.leaderstats.Stage.Value = touch.Name
end
end
end)
plr.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")
hrp:GetPropertyChangedSignal("CFrame"):Wait()
hrp.CFrame = checkpoints[plr.leaderstats.Stage.Value].CFrame
humanoid.Touched:Connect(function(touch)
if touch.Parent == checkpoints then
if (tonumber(touch.Name)and tonumber(touch.Name)>tonumber(plr.leaderstats.Stage.Value))or touch.Name == "End" then
plr.leaderstats.Stage.Value = touch.Name
end
end
end)
humanoid.Died:Connect(function()
hrp.CFrame = checkpoints[plr.leaderstas.Stage.Value].CFrame
end)
end)
end)
You’re checking for when the humanoid dies then moving the dead body to the checkpoint. Move the character when it gets added
How do i do this. A code sample from my script will be helpful.
1 Like
This is the part that’s not necessary.
I’m still unsure of what is happening in your game. What does the provided code sample do? How is this different from what you want it to do?
I want them to spawn at their last touched checkpoint when they die. My game is an obby.
Yes but what is the code sample you’ve provided doing? Please provide screenshots, output, videos.
The code sets the person’'s checkpoints when they touch a checkpoint and is supposed to spawn them there when they die.
Ok and you need help with the spawning part? It’s setting the checkpoint just fine?
If so it may be related to
You’re just setting the HumanoidRootPart CFrame and not setting the entire character to the CFrame. I don’t know if that’s what is causing it, but you may want to consider using SetPrimaryPartCFrame()
This is the problem. I am on stage 2 but it spawns me at stage 1.
Also, how would I do the set primary cframe (code sample will help).
I’m not allowed to write your code for you. You still need to search around to see if you can get a good resource even if it is a reply.
Anyways, I think you should really use the debugger or troubleshoot your project more carefully.
2 Likes