What I would do is create a model which holds all of the checkpoints. Name each checkpoint 1, 2, 3, etc. in order. The player’s starting checkpoint is 1 (do this all in a local script). Once the player touches the checkpoint which is 1 + tonumber(current checkpoint name), then move the star to that new checkpoint + vector3.new(0,~10,0) so that the star is above the ground.
it is a good idea to tell the truth i am not very good as french i already have what you tell me for the checkpoints must i see how i can move the star
Ah, okay. To move the star, simply set its position to the CURRENT CHECKPOINT + Vector3.new(0,5,0) . Do this with a local script so everyone sees the star at their own checkpoint.
Just like what @roblox_user_54556995 said, you could create a model contained with checkpoints, but anyway, here is an example code:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local CheckpointModels = {Checkpoint1, Checkpoint2, Checkpoint3}
for i, v in pairs(CheckpointModels) do
v.Touched:Connect(function(hit)
if hit.Parent:WaitForChild("Humanoid") then
local Humanoid = hit.Parent:WaitForChild("Humanoid")
if Humanoid.Health == 0 then -- When the player dies then it will make sure to check when it will come back to normal
if Humanoid.Health == 100 then
hit.Parent:WaitForChild("HumanoidRootPart").CFrame = v.CFrame
end
end)
end
end
end
Ignore my bad indenting, also this is an example code, you can code a different one yourself.
I’m just making sure if the humanoid’s health is 0 so that when the player dies and comes back alive then it will move it’s HumanoidRootPart’s CFrame to the checkpoint. Is there a way where I could make sure the character comes back to 100 health, though?
You do realize both of those fire at once? If a humanoid’s health is at 0, it can’t immediately be at 100 all of the sudden. That code is impossible to run.
So how do we check when the character dies and comes back alive to move to the checkpoint’s CFrame. This code won’t work as it will not move the character because it died.
if Humanoid.Health == 0 then
HumanoidRootPart.CFrame = Checkpoint.CFrame
end
Humanoid.Died:Connect(function()
local func
func = plr.CharacterAdded:Connect(function()
--Do Whatever
func:Disconnect() -- at the end of the function
end)
end)
Here is a script you should put in ServerScriptService
--// Server code! Put in game.ServerScriptService
local spawnOffset = Vector3.new(0,1,0) -- Spawn offset. Change this as needed.
local checkpointCooldown = 5 -- Minimum time to be allowed to switch checkpoints
game.Players.PlayerAdded:Connect(function(player)
local lastCheckpoint = nil -- You don't start with a checkpoint
local checkpointGlobalData = Instance.new("ObjectValue",player) -- A variable stored in the player, telling the client the current checkpoint.
checkpointGlobalData.Value = lastCheckpoint
checkpointGlobalData.Name = "checkpoint"
player.CharacterAdded:Connect(function(character)
if lastCheckpoint then -- If a checkpoint is reached
local root = character:WaitForChild("HumanoidRootPart")
root.CFrame = lastCheckpoint.CFrame + spawnOffset
end
local checkpoints = workspace:WaitForChild("Checkpoints") -- Assuming your checkpoints are some sort of BasePart or Model.
local hum = character:WaitForChild("Humanoid")
local debounce = false
hum.Touched:Connect(function(partTouched,limbAffected) -- Yes, humanoid has a touched event too.
if not debounce and hum.Health > 0 and partTouched:IsDescendantOf(checkpoints) then -- If not on cooldown, the player is alive, and if the player touched a checkpoint.
lastCheckpoint = partTouched
checkpointGlobalData = lastCheckpoint
debounce = true
wait(checkpointCooldown)
debounce = false
end
end)
end)
end)
Here is a script to be put in client (to make checkpoints disappear). Put it in StarterPlayerScripts
--// Client script. Put in StarterPlayerScripts!
local checkpointData = game.Players.LocalPlayer:WaitForChild("checkpoint") -- Get the checkpoint data variable
local lastCheckpoint = checkpointData.Value -- Extra variable to store recent checkpoint history
checkpointData.Changed:Connect(function() -- Fires when checkpoint changes
if lastCheckpoint then
lastCheckpoint.Transparency = 0
end
local checkpointPart = checkpointData.Value -- The checkpoint
lastCheckpoint = checkpointPart
checkpointPart.Transparency = 1
end)
Yes, i know hence i said your method was more elegant.
The code i’ve supplied can still be used in some instances aswell so that the code does not yield.
Incase the user ever wants to add other code within.
I will try that thank you! on the other hand I have a question how do I reset my backup because my game saves my checkpoints and for my tests it ruins everything how can I reset this?