# Operator Doesn't Work Correctly

OH WAIT i use the # method in the client for my progress bar and my skip stage button

image

and was that where the 10 was coming from or was it coming from the server script?

from the client. But what difference does it make anyways?

The instances arent replicated to the client immediately so the client only believes 10 objects exist instead of all of them.

You can make the CheckpointAmount accurate by changing it to
local CheckpointAmount = #Checkpoints:GetChildren()
Checkpoints.ChildAdded:Connect(function()
CheckpointAmount+=1
end)

so what do i need to do to fix that issue

Then that is your issue. On the client, not everything is loaded in the workspace. Use this pattern instead:

local function onCheckpointAdded(checkpoint: Instance): ()
    if checkpoint:IsA("BasePart") then
        -- update # checkpoints
    end
end

Checkpoints.ChildAdded:Connect(onCheckpointAdded)

for _, child: Instance in Checkpoints:GetChildren() do
    task.spawn(onCheckpointAdded, child)
end

Edit: If you want to just get the guaranteed amount of checkpoints without needing to load all the checkpoints, you can add an attribute to the Folder on the server.

1 Like

even tho i added that
image
it still print that
image

This is the client script? The other children may already be detected by the client

You can see which checkpoints are replicated to the client by clicking the play button and going to explorer and the checkpoints folder.

image
oh dam

Do you have streaming enabled on? If so, parts far away wont load until you get close to them and the client wont know they exist.

yeah its enabled in thw workspace

No, keep your original code. There is no need to do that on the server. Refer to this post edit for the solution: # Operator Doesn't Work Correctly - #32 by OniiSamaUwU

Either turn it off or you can just add the touched event under the Child added function

This works but they dont need to just update the number of checkpoints, The touched event has to be connected too

cant i just create a value in like replicatedstorage and then fill the value in the server and then catch the value in the client?

Yeah. If you need the number of checkpoints to be displayed in a UI or smthn. I remember you said there was a progress bar so you need to either use a remoteEvent/function or turn streaming enabled off or have a NumberValue in replicated storage with the numbe of total checkpoints. I would use the remote function, but if the map isnt large you can turn streaming enabled off.

i made a value now that is getting filled by the server and used by the client and for safety reasons i also made a repeat until loop so the value mustn’t be 0 and it works

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.