Checkpoint obby indicator

Hello, I’m designing an Obby game.

Actually, I designed it, but I would like to bring something new to put it back on roblox.

I would like the star to disappear for the player when he goes to the checkpoint and only for him and for the star of the next checkpoint to appear

see

thanks you

1 Like

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.

1 Like

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.

1 Like

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.

1 Like

What is this? This is the weirdest code segment I’ve ever seen, as it will never fire.

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

You have to wait for a character respawn, and then call the checkpoint function. I will upload code momentarily to show what I mean about that :wink:

2 Likes

What you’re trying to say is something like this:

Humanoid.Died:Connect(function()
local func
func = plr.CharacterAdded:Connect(function()
--Do Whatever
func:Disconnect() -- at the end of the function
end)
end)
1 Like

Just do plr.CharacterAdded:Wait().

2 Likes

Wait, so if you assign a function to the variable would the function still run?

yes unless the function you make has to be called.

Reffer to what @iGottic said, His version’s more elegant.

Okay, thanks for picking that out @iGottic! Here’s the code now:

(Also I am not trying this on studio, I am typing this on mobile)

1 Like

Okie, I have some code for you @DonooZeus!

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)

Hope I helped, please give credit if using :slight_smile:

1 Like

@Tamzy3D @InternallyAmplified That code works, but is fairly inefficient. Try checking out my code I uploaded :slight_smile:

@DonooZeus I do ask you set my reply as a solution, so newcomers to this topic can see how it’s done.

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.

1 Like

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?

I tried and it doesn’t work for me