Dictionary returning ambiguous results when sent from server to client

Hi there,

I’m sending a dictionary with information from the server to the client that looks like this:

server script

local script

Of course I expect the structure of the dictionary received by the client to be the same each time, however when testing, some play sessions represent the ‘correct’ data (how I expect it to look) and other times it doesn’t which results in my code throwing an error.
It’s pretty 50/50, some sessions the client will receive the correct dictionary, some sessions the client won’t.

How it’s sometimes received (what I want):
image

How it’s also sometimes received (what I don’t want):
image

As seen in the image above, at LoadingBgSplash:29, what’s been printed is no longer a dictionary but the value that is inside that dictionary.
I have no clue why I’m receiving these ambiguous results. Any help would be appreciated!

1 Like

Try printing before firing the remote what areaFolder is. The Instance, I mean. On the server.

1 Like

Hmm, after doing that I’ve realised something.

server script

In the cases where the dictionary is what I expect it to be on the client, the second print statement in the img above will print. However, in the other cases the second line won’t print anything at all?
I’m hella confused, as I’m not altering the value of areaFolder in any way so I’m not sure why print statement 1 prints when print statement 2 doesn’t?

Does the connected function works immediately after the first prints or does it waits until it is fired?

The callback functions wait until they’re fired

and when it is supposed to fire, it doesnt print the line 17?

i would then suggest something:

zone.playerEntered:Connect(function(plr: Player)
	local areaFolder

	for _i areaFolder in accessibleAreas do
		local teleportHitbox: Model = areaFolder:FindFirstChild("TeleportHitboxZone", true)
		if not teleportHitbox then continue end
		local zone = Zone.new(teleportHitbox)
	end
	Remote.Gui:ChangeGuiStatusRemote:FireClient(plr, "loadingBgSplash", true, {areaFolder - areaFolder})
end)

Well my code is probably wrong but my idea is to use a loop inside the connected event

Seems like you are moving the areaFolder around in your game. Maybe you move it from Workspace to ServerStorage or similar. What exactly is in the areaFolder variable?

I appreciate you helping however this won’t work, as the zone (what .playerEntered is being called on) gets created within the loop and can’t be referenced outside the loop which is what you’re doing

Nope, which is why I’m so confused.
image
This is the folder that is referenced by areaFolder, it remains in the location I want it to be in.

then why not doing a local function with your code and inside the connect event if areaFolder is nil then calling again your function? something like:

local function GetArea()
	for _i, areaFolder in accessibleAreas do
		local teleportHitbox: Model = areaFolder:FindFirstChild("TeleportHitboxZone", true)
		if not teleportHitbox then continue end
		local zone = Zone.new(teleportHitbox)

		zone.playerEntered:Connect(function(plr: Player)
			if not areaFolder then
				GetArea()

			else
				Remote.Gui:ChangeGuiStatusRemote:FireClient(plr, "loadingBgSplash", true, {areaFolder - areaFolder})

			end
			
		end)
	end
	
end

Not sure if it will works to be honest but this is my only idea