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

How do I make it so that the only checkpoint you can get is the next stage's checkpoint in my obby?

Asked by 1 year ago

Currently you can get any checkpoint, whether it's behind you, or 5 stages ahead of you, I want to make it so that only the next stage's checkpoint can be gotten. Here is my checkpoint script in ServerScriptService:

local Players = game:GetService('Players')

Players.PlayerAdded:Connect(function(player)
    local stage = player:WaitForChild("leaderstats"):WaitForChild('Stage')
    player.CharacterAdded:Connect(function(character)
        local checkpoint = game.Workspace.Stages:FindFirstChild(stage.Value)
        delay(.01, function() 
            character:SetPrimaryPartCFrame(checkpoint.CFrame + Vector3.new(0,10,0))
        end)
    end)
end)

And here is the checkpoint script that goes in with my stages in the "Stages" folder:

for i,v in pairs(script.Parent:GetChildren()) do
    if v:isA("Part") then
        v.Touched:Connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Humanoid").Health >= 1 and v.Name ~= "0" then
                game.Players:FindFirstChild(hit.Parent.Name).leaderstats.Stage.Value = v.Name
            end
        end)
    end
end

2 answers

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago
for i,v in pairs(script.Parent:GetChildren()) do
        if v:isA("Part") then
            v.Touched:Connect(function(hit)
            local character = hit.Parent
            local player = game.Players:GetPlayerFromCharacter(character)
            if player then
                        local touchedstage = tonumber(v.Name)
                if touchedstage == (player.leaderstats.Stage.Value + 1) then
                    player.leaderstats.Stage.Value = touchedstage
                end
                    end
            end)
        end
end
0
Didn't work BunjiBloxxer 51 — 1y
0
was an error in code, fixed it. BulletproofVast 1033 — 1y
0
Worked, thanks! BunjiBloxxer 51 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

I can't tell you exactly where to put this. Or exactly how your own code works (I'm new and never worked with checkpoint systems), but you might want to add and attribute to the checkpoints (click "add attribute" in the properties tab) and make a Boolean value. Name it "isTouched", and set it to false.

Now, add this line of code, when the player hits the checkpoints and saves data there:

game.Workspace.CheckpointTest.isTouched == true

Now, when you detect the hit, you want to add this with the word "and"

game.Workspace.CheckpointTest.Touched:Connect(function(hit)
    if hit:FindFirstChild:("Humanoid") then
        if game.Workspace.CheckpointTest.isTouched == true then
            --tp player back to other checkpoint
        end
    end
end)
0
Probably not going to work.... but try it. fiddyfiddler 18 — 1y

Answer this question