I'm a little confused

So I’m making a game with a friend, and for this simple obby checkpoint system, I seem to be stumped!

Here is my code:

-- made by recanman
for _, child in ipairs(script.Parent:GetChildren()) do
	if (child:IsA("Folder")) then
		for _, killpart in ipairs(child.Obby.KillParts:GetChildren()) do
			if (killpart:IsA("Part")) then
				killpart.Touched:Connect(function(hit)
					local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
					
					if (plr ~= nil) then
						plr.Character.Humanoid.Health = 0
					end
				end)
			end
		end
	end
end

for _, child in ipairs(script.Parent:GetChildren()) do
	if (child:IsA("Folder")) then
		child.Base.Touched:Connect(function(hit)
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			if (plr ~= nil) then
				local stage = plr.Character.CurrentStage.Value
	
				if (tostring(stage + 1) == child.Name) then
					stage = stage + 1
					wait(1)
				end
			end
		end)
	end
end

This is not an obby game, thats why the stage is not a leaderstats.

My problem:

print(tostring(stage + 1) == child.Name) -- returns true

if (tostring(stage + 1) == child.Name) then -- doesn't run

I’ve tried tonumber and nothing at all, but nothing is working right now. This seems like an awfully simple fix, and I’m out of my mind. Any help would be appreciated, thanks for reading. :slightly_smiling_face:

2 Likes

You could simplyify this by marking the parts you want to kill the player with Tagging plugin and then using collection service

I understand what collectionservice is, but in this case (for simplicity) i dont wanna use it.

Hello! Your if statement does in fact return true and does run, however the contents within it are what’s messing things up.

The value stage is currently defined as a number, and has no correlation to the instance CurrentStage. When you’re adding 1 to stage, you’re only increasing that variable and not the CurrentStage instance that other scripts probably check.

You can quite easily solve this issue by defining stage as plr.Character.CurrentStage and not plr.Character.CurrentStage.Value. Now, add .Value to all the places where stage is used.

1 Like

Ha!
The stupid little typos people can make! Thank you so much, you really helped.

1 Like