Welcome to this Obby Checkpoint Tutorial For Noobs. I will cover everything you need to know about Checkpoints and having the players respawn at your checkpoint.
Copy Code For Lazy People:
local Players = game:GetService("Players") -- Player Service
local ServerStorage = game:GetService("ServerStorage") -- Server Storage
local checkpoint = script.Parent -- Getting The Checkpoint
function onTouched(hit)
if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then -- Getting The Hit.Parent
local player = Players:GetPlayerFromCharacter(hit.Parent) -- Checking If Player
local checkpointData = ServerStorage:FindFirstChild("CheckpointData") -- This Line Is Not Necessary
if not checkpointData then
checkpointData = Instance.new("Folder") -- Creating The Folder For Checkpoint Data
checkpointData.Name = "CheckpointData"
checkpointData.Parent = ServerStorage
end
local userIdString = tostring(player.UserId)
local checkpointValue = checkpointData:FindFirstChild(userIdString) -- Getting The User Id String
if not checkpointValue then
checkpointValue = Instance.new("ObjectValue") -- Creating A New User Id String
checkpointValue.Name = userIdString
checkpointValue.Parent = checkpointData
player.CharacterAdded:connect(function(character) -- Getting The Player Character
wait() -- Waiting Until The Play Character Is Added
local storedCheckpoint = ServerStorage.CheckpointData[userIdString].Value -- Checking To Make Sure It's The Correct Person
character:MoveTo(storedCheckpoint.Position + Vector3.new(math.random(-4, 4), 4, math.random(-4, 4))) -- If The Character Dies It Will Teleport To Checkpoint
end)
end
checkpointValue.Value = checkpoint -- Making Sure It's The Right Checkpoint
end
end
checkpoint.Touched:Connect(onTouched) -- Starting The Function When The Checkpoint Is Touched
Create A Script In Your Checkpoint And Put This Code In There
Step 1
Creating Your Part
Create a part in Workspace.
You can name your part if you want but I name my part “Checkpoint”
Step 2
Getting Services
After Creating Your Part you want to add in a script into your part.
First thing you want to do is get both of your services
local Players = game:GetService("Players") -- Player Service
local ServerStorage = game:GetService("ServerStorage") -- Server Storage
Step 3
Getting Your Part Variable
After getting your services you want to get your part variable
local checkpoint = script.Parent -- Getting The Checkpoint
Step 4
Creating Your Function
After you’ve got your variables and services you want to create your Function
function onTouched(hit)
if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then -- Getting The Hit.Parent
local player = Players:GetPlayerFromCharacter(hit.Parent) -- Checking If Player
local checkpointData = ServerStorage:FindFirstChild("CheckpointData") -- This Line Is Not Necessary
if not checkpointData then
checkpointData = Instance.new("Folder") -- Creating The Folder For Checkpoint Data
checkpointData.Name = "CheckpointData"
checkpointData.Parent = ServerStorage
end
local userIdString = tostring(player.UserId)
local checkpointValue = checkpointData:FindFirstChild(userIdString) -- Getting The User Id String
if not checkpointValue then
checkpointValue = Instance.new("ObjectValue") -- Creating A New User Id String
checkpointValue.Name = userIdString
checkpointValue.Parent = checkpointData
player.CharacterAdded:connect(function(character) -- Getting The Player Character
wait() -- Waiting Until The Play Character Is Added
local storedCheckpoint = ServerStorage.CheckpointData[userIdString].Value -- Checking To Make Sure It's The Correct Person
character:MoveTo(storedCheckpoint.Position + Vector3.new(math.random(-4, 4), 4, math.random(-4, 4))) -- If The Character Dies It Will Teleport To Checkpoint
end)
end
Step 5
Making Sure It's The Right Checkpoint
Making sure that when a player touches the checkpoint it is the correct checkpoint.
checkpointValue.Value = checkpoint -- Making Sure It's The Right Checkpoint
end
end
Step 6
Starting The Function
Now we will start the Function when the part is touched!
checkpoint.Touched:Connect(onTouched) -- Starting The Function When The Checkpoint Is Touched
Final Product
Final Script
Once your done you should have a script that looks something like this:
local Players = game:GetService("Players") -- Player Service
local ServerStorage = game:GetService("ServerStorage") -- Server Storage
local checkpoint = script.Parent -- Getting The Checkpoint
function onTouched(hit)
if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then -- Getting The Hit.Parent
local player = Players:GetPlayerFromCharacter(hit.Parent) -- Checking If Player
local checkpointData = ServerStorage:FindFirstChild("CheckpointData") -- This Line Is Not Necessary
if not checkpointData then
checkpointData = Instance.new("Folder") -- Creating The Folder For Checkpoint Data
checkpointData.Name = "CheckpointData"
checkpointData.Parent = ServerStorage
end
local userIdString = tostring(player.UserId)
local checkpointValue = checkpointData:FindFirstChild(userIdString) -- Getting The User Id String
if not checkpointValue then
checkpointValue = Instance.new("ObjectValue") -- Creating A New User Id String
checkpointValue.Name = userIdString
checkpointValue.Parent = checkpointData
player.CharacterAdded:connect(function(character) -- Getting The Player Character
wait() -- Waiting Until The Play Character Is Added
local storedCheckpoint = ServerStorage.CheckpointData[userIdString].Value -- Checking To Make Sure It's The Correct Person
character:MoveTo(storedCheckpoint.Position + Vector3.new(math.random(-4, 4), 4, math.random(-4, 4))) -- If The Character Dies It Will Teleport To Checkpoint
end)
end
checkpointValue.Value = checkpoint -- Making Sure It's The Right Checkpoint
end
end
checkpoint.Touched:Connect(onTouched) -- Starting The Function When The Checkpoint Is Touched