Argument 1 missing or nil

Hey there! I’m having a problem with PublicAsync which is that it gives me this error saying “Argument 1 missing or nil” although clearly there is an argument 1 there.

The line making the error (I made it FindFirstChildWhichIsA(“Player”) because there is only one player in a server):

MessagingService:PublishAsync("SetRooms", GetServers:InvokeClient(game.Players:FindFirstChildWhichIsA("Player")))

Any help would be appreciated!

make sure that your function “GetServers” is actually returning something

These kinds of functions FindFirstChildWhichIsA would not 100% return back the Player Instance, as it’ll either return back the Player or nil

If you want to handle some sort of sanity check to make sure that doesn’t happen, implement something like this so that you check that there is a valid Player in the Players Service to Invoke the Client on

local PlayerCheck = game.Players:FindFirstChildWhichIsA("Player")

if PlayerCheck then
    MessagingService:PublishAsync("SetRooms", GetServers:InvokeClient(PlayerCheck))
end

Doesn’t work, I think my method doesn’t work so I’ll try something else. Thank you for the help!

Are you running this before the player has even joined the game? The server starts and Lua code begins running before players even join, so if this is running immediately after the server starts there will be no player returned by game.Players:FindFirstChildWhichIsA("Player").

Oh you’re right, but in any way what I did won’t work with my system because I didn’t think it out that much.