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

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

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

✓ Accepted answer
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

3 comments

0

Didn't work

0

was an error in code, fixed it.

0

Worked, thanks!

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)

1 comment

0

Probably not going to work.... but try it.

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