One thing that confused me a lot ever since i began to script was obby checkpoints. And i wanted to know how i would be able to create one. If you could at least tell me the process of what is done to create such thing, PLEASE do.
Here is a teleport script you put in ServerScriptService
.
Name your checkpoints "Checkpoint1"
, "Checkpoint2"
, and so on.
If you want more than one checkpoint, just add more parts with the appropriate names.
The player will automatically respawn at the highest-numbered checkpoint they’ve touched.
Simple, but it works!
Remember if you don’t want them to collide with the checkpoint make the part cancollide = false
local Players = game:GetService("Players")
local checkpoints = {}
local function getCheckpointNumber(name)
local n = string.match(name, "^Checkpoint(%d+)$")
return n and tonumber(n)
end
for _, part in ipairs(workspace:GetChildren()) do
local num = getCheckpointNumber(part.Name)
if part:IsA("BasePart") and num then
part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local current = checkpoints[player.UserId]
if not current or num > current.num then
checkpoints[player.UserId] = {num = num, cframe = part.CFrame}
end
end
end)
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local hrp = char:WaitForChild("HumanoidRootPart")
local data = checkpoints[player.UserId]
if data then
hrp.CFrame = data.cframe + Vector3.new(0, 3, 0)
end
end)
end)
And if you want to do it yourself here is all the links:
- https://create.roblox.com/docs/reference/engine/classes/BasePart/Touched
- https://create.roblox.com/docs/reference/engine/classes/Players/PlayerAdded
- https://create.roblox.com/docs/reference/engine/classes/Player/CharacterAdded
- https://create.roblox.com/docs/reference/engine/classes/Players/GetPlayerFromCharacter
- https://create.roblox.com/docs/reference/engine/datatypes/CFrame
- Vector3 | Documentation - Roblox Creator Hub
- string | Documentation - Roblox Creator Hub
you can basically change the spawnpoint of the player, for instance
local checkpoint = script.Parent
checkpoint.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild
if not humanoid then return end
humanoid.SpawnLocation = checkpoint
btw the checkpoint needs to be a spawn location
Hope this helps!
Sadly, if the player touched a checkpoint earlier than the one they’re on, it will still make it their checkpoint.
wow… thanks so much man! This is actually extremely helpful. I really need to look at the API more.
No problem. Glad it helped you!