Player.UserId Not Working

Server Script

local module = require(ReplicatedStorage.ModuleScript)

game:GetService("Players").PlayerAdded:Connect(function(player)

    module.PrintUserId(player)

end)

Module Script

local module = {}

function module:PrintUserId(player)
    print(player.UserId) -- Outputs nil
end

return module

When I try to get the UserId of a player from player it always returns nil, am I doing something wrong with such a simple task.
I have tried instead firing the player.UserId to the module, but it prints out a table address :confused:

1 Like

You are calling the function using the dot . operator, but defining it with the colon : operator. Using the colon results in a hidden parameter, self being passed as the first parameter of the function. Switching both of them to the dot operator would fix it. Alternatively, you could switch both to the colon operator, but you would need to add a self parameter to your function, so I’d rather do the former.

Similar issue (with a better description than mine):

Same code, but changing the colon to a dot:

function module.PrintUserId(player) 
    print(player.UserId)
end
1 Like

Thank you so much, sometimes tiny problems get me haha

1 Like