Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How Do I Add An Obby Stage Leaderboard?

I want to make a level where if you hit a checkpoint, it puts the counter up by one, but I don't want it so that it happens multiple times. I already set up the the stage variable on the leaderboard, here is the code:

local function onPlayerJoin(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player

local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 0
stage.Parent = leaderstats

end

game.Players.PlayerAdded:Connect(onPlayerJoin)

Edit- It only highlighted some of the code as code. from the colon to this is all code

and now I want it so that when you hit a different checkpoint, the number changes. How do I do this?

1 comment

0

Maybe for each level, you have a spawnpoint, and add a touched script, that connects to a function that adds one point to the players leaderstat?

1 answer

Make a folder inside of a workspace and call it checkpoints (you dont have to). Then for checkpoints, make a part and call it number by stage to make it ALOT easier, example: Stage 1 checkpoint will be named "1" and put checks into the folder. Then make a script:

local checkpoints = script.Parent.Checkpoints:GetChildren() -- location to checkpoints folder (customize it)
for _, checkpoint in pairs(checkpoints) do -- function to all checkpoints
	checkpoint.Touched:Connect(function(hit) -- on touch
		if hit.Parent.Humanoid then -- if player then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- gets players
			local stage = player:WaitForChild"leaderstats":WaitForChild"Stage" -- gets stage
			if checkpoint.Name + 0 > stage.Value then -- if stage is higher then
--			if checkpoint.Name + 0 == stage.Value + 1 then -- if you dont want anyone to skip stages
				stage.Value = checkpoint.Name + 0 -- i put + 0 there because otherwise it breaks (attempt to add string on a value)
			end
		end
	end)
end

Hope it helps.

This discussion is preserved as it was. New answers, comments, and votes are closed.