Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Do I Add An Obby Stage Leaderboard?

Asked by 4 years ago
Edited 4 years ago

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?

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? Aztralzz 169 — 4y

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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.

Ad

Answer this question