Second argument is nil in OnClientEvent

I’m using FireAllClient from server and sending two arguments, but in OnClientEvent() I’m receiving just first argument and second argument as nil.

I do have checked the arguments from the server-side and both have a valid value (Boolean, Number).

Here is an example.
Server Side Code: Firing All Clients

remoteEvents.characterSpawned.OnServerEvent:Connect(function(thePlayer)
	local timer = getServerTimerValue()
	thePlayer:LoadCharacter() -- Built-in function to load character
	wait(3)
	remoteEvents.characterSpawned:FireAllClients(thePlayer, timer)
end)

Client-side code: Receiving client event

characterSpawnedEvent.OnClientEvent:Connect(function(localPlayer, serverTimer)
	timer.Value = serverTimer
	
	if not (localPlayer == playerService.LocalPlayer) then
		return
	end
	
	wait(5)
	local tweenPlayer = tweenService:Create(
		timeContainer,
		TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out),
		{Position = UDim2.new(0.5,0,0,5), AnchorPoint = Vector2.new(0.5,0)}
	)
	tweenPlayer:Play()
end)

and I also found the issue.
I was actually sending NumberValue object instance instead of its value and it seems like FireAllClient method doesn’t support this type of data.

remoteEvents.characterSpawned:FireAllClients(thePlayer, timer) - Wrong
remoteEvents.characterSpawned:FireAllClients(thePlayer, timer.Value) - Right

Try this:

remoteEvent.OnClientEvent:Connect(function (serverTuple1,serverTuple2)
print(tostring(serverTuple1) .. " | " ..tostring(serverTuple2) )
end)

remoteEvent.OnClientEvent does not return a table.

Actually, you can pass on a table but it must not be a mixed table.

1 Like

It would be mixed table, because first value is boolean and second is number

When I say a mixed table, I mean this:

local randomTable = {
    1,
    a = 2
}

A normal table is like this:

local randomTable = {
    1,
    2
}
1 Like

If second argument is nil, try fixing this by adding print that will print second argument value (do it on server side). You may see, that the second value is nil before sending it- you may need to fix something in Server Script.

Could you include the server side code so we can get a better idea on what’s going on?

but from what I can see you should be packing the args if you want them to be in table format, assuming you’re firing the event like event:FireAllClients(true, 1)

event.OnClientEvent:Connect(function(...)
	local args = {...}
	print(args[1], args[2])
end)
1 Like

I have checked the values from server side before sending it to client and these are fine…

Can you send the event:FireAllClients code on your server, please?

Can you link the fragment of the server code or tell me how does the second value look like?

@Jermartynojm, @itsrenderman,
I’ll update the question when I get to home…

1 Like

The first one is called a dictionary, the second is an array.

The first one is a mixed table, second is an array. There is no dictionary on that.

@Quwanterz @Little_Joes
Second argument is just a number…