# Operator Doesn't Work Correctly

so i was creating a checkpoint system and the system works completely fine expect for one thing and that is the # operator doesnt really work. I grouped all of my checkpoint parts in a folder and i also created the main script in the folder. and currently i have like 44 checkpoints and i was trying to get the max checkpoint per script so i can code some barriers for the skip stage button ohterwise it will get buggy and even tho i have like 44 checkpoints currently if i print smt like (#CheckpointFolder:GetChildren() - 1) it gives me numbers like 10 or smt. btw i did -1 because i also gotta remove the script object from the amout so i only have the checkpoints. But still it doesnt give me the right checkpoint amount

Is this a Local Script or a Server Script? And did you make sure you aren’t destroying the checkpoints at some point?

it is a server script placed into the same checkpoint folder

and im also not destroying stuff

are the checkpoints all individually in the folder or is there sub-folders that are children of the “CheckpointFolder”? If there are subfolders then GetChildren will only count the subfolders + the script and not the descendants of those folders

1 Like

no they are all on the same layer


like that

Could you show part of the checkpoint script so I have more context?

If i print that
image
it prints 10 or sum

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Modules = ReplicatedStorage:WaitForChild("Modules")
local TypePlayer = require(Modules:WaitForChild("TypePlayer"))
local ClearedSound = script:WaitForChild("ClearedSound")
local ClearedVFX = script:WaitForChild("ClearedVFX")
local Checkpoints = script.Parent

Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"
	
	local Stage = Instance.new("IntValue", Leaderstats)
	Stage.Name = "Stage"
	Stage.Value = 0
end)

for _, Checkpoint in pairs(Checkpoints:GetChildren()) do
	if Checkpoint:IsA("BasePart") then
		Checkpoint.Touched:Connect(function(OhterPart)
			if OhterPart.Parent:FindFirstChild("Humanoid") then
				local Character = OhterPart.Parent
				local Player = Players:GetPlayerFromCharacter(Character)
				
				if Player then
					local Leaderstats = Player:WaitForChild("leaderstats")
					local Stage = Leaderstats:WaitForChild("Stage")
					
					if tonumber(Checkpoint.Name) > Stage.Value then
						Stage.Value = tonumber(Checkpoint.Name)
						
						task.spawn(function()
							local Attachment = Instance.new("Attachment", Checkpoint)
							TypePlayer:PlayParticles(ClearedVFX, "Emit", Attachment)
						end)

						task.spawn(function()
							TypePlayer:PlaySound(ClearedSound, Checkpoint)
						end)
					end
					
					Player.CharacterAdded:Connect(function(Chr)
						local FoundCheckpoint = Checkpoints:WaitForChild(tostring(Stage.Value))
						
						Chr:MoveTo(FoundCheckpoint.Position + Vector3.new(0, FoundCheckpoint.Size.Y / 2, 0))
					end)
				end
			end
		end)
	end
end
``

local Checkpoints = script.Parent
Checkpoints.ChildAdded:Connect(function(child)
print(child)
end

Try adding this right under your declaration for the checkpoints variable and let me know if it prints anything

This shouldn’t happen on the server. Are all your parts anchored? Are you seeing all 44 in the explorer when that line runs?

all checkpoints
are anchored yeah

Right, but do you see all of them in the explorer upon hitting play? Are all of the checkpoint’s Archivable property set to true?

When the game runs are all the checkpoints in the explorer under the checkpoint folder?

yeah Archivable is true for all parts

yeah they all exist right in the start

and does this print any objects?

yeah i tried that but it prints nothing

On the server, it is guaranteed that the game and workspace will load completely before the scripts run. I’ve tried running the same code and it is working fine on my end.

You are reading the #checkpoints on the server, not the client, right? Can you add a task.wait(1) before you print out the #checkpoints and screenshot your Explorer for me.