Obby Checkpoints Script

I am new to lua scripting and tried to create an obby checkpoint system for my first obby game but it doesn’t seem to work, I will attach some screenshots of what I’ve done so far, comments are welcome.


checkpoint explorer

2 Likes

It seems like your code is on the right track! Here are some comments on your script:

  1. Make sure that the script is a child of the part that will serve as the checkpoint. From your screenshot, it looks like the script is a child of the workspace, which might not work as intended.
  2. In the onTouch() function, you’re currently using player.Character.Humanoid to get the player’s humanoid. However, if the player dies and respawns, player.Character will be nil until they respawn again. You can use the CharacterAdded event to update the humanoid variable when the player respawns:
local humanoid = nil

function onCharacterAdded(character)
   humanoid = character:WaitForChild("Humanoid")
end

player.CharacterAdded:Connect(onCharacterAdded)
  1. You’re using RemoteEvents to communicate between the server and the client, which is a good approach. However, you’re sending the checkpoint number as an argument to the event, which can be exploited by players to skip checkpoints. Instead, you can send the instance of the checkpoint part itself and check if the player touches the correct checkpoint:
function onTouch(otherPart)
    local character = otherPart.Parent
    if character and character:FindFirstChild("Humanoid") and character.Humanoid.Health > 0 and otherPart == script.Parent then
        if not checkpointPassed then
            checkpointPassed = true
            game.ReplicatedStorage.CheckpointReached:FireClient(player, script.Parent) -- send the checkpoint part itself as an argument
        end
    end
end
  1. Finally, make sure that you’re adding the onTouch() function to the Touched event of the checkpoint part:
script.Parent.Touched:Connect(onTouch)

For all these people apes that says that I use ChatGPT explain how did I scan the text with the “ChatGPT”

2 Likes

As @HolisThaDev made all great suggestions, including capitalizing “Humanoid” as it is case sensitive when in quotes, you had left it lower case in your “local hum” variable… but they fixed it in their suggestion.

It’s possible to scan the text with Chat GPT, its not stupid after all. But good Support Post!

2 Likes

bro really thinks iam a bot with 2329042349023 ai integrated

1 Like

Go the last end and go down a line then paste this in:

for i,v in pairs(workspace.Checkpoints:GetChildren()) do -- gets all checkpoints in the folder
	v.Touched:Connect(function(hit) -- when one of the checkpoints is touched
		local char = hit.Parent -- lets say the leg hit the checkpoint, the leg's parent would be the character
		local player = game.Players:GetPlayerFromCharacter(char) -- getting the player in game.Players from the character
		local humanoid = char:WaitForChild("Humanoid") -- gets the humanoid
		if player and humanoid then -- checks if there is a player with the character's name in game.Players, also checks if the character has a humanoid
			if humanoid.Health <= 0 then return end -- if the player is dead then returns it, basically doing nothing from this point on
			if player.leaderstats.Stage.Value == tonumber(v.Name) - 1 then --checks if the checkpoint touched is the next checkpoint
				player.leaderstats.Stage.Value += 1 -- adds 1 to the existing stage on the leaderstats
			end
		end
	end)
end

Also, don’t use the roblox spawns, use a regular part that teleports you to whichever stage you were on

if you don’t understand something or need help with anything, let me know

3 Likes

thanks, im gonna try with this!

Thankss!! This is really helpful, it worked, but now im reading the whole code in order to understand how works, just a last thing, how can i practice roblox coding??

Well I mainly got used to lua simply by watching videos like tutorials and when I was stuck, I would look on the devforum trying to understand as much as I can piece by piece. I am nowhere near a good scripter as most people, however I have some knowledge that I try and pass on to others like you! :smiley:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.