Can I get the user ID from a server script?

Hello, I am trying to get the user id from a script so I can set an npc’s appearance to the local players appearance and it wont work on local scripts this is the code I have.

local plr = game.Players.PlayerAdded
local id = 184878837
local Models = game.Players:GetCharacterAppearanceAsync(id)
Models.Parent = script.Parent
wait()
for i,v in pairs(Models:GetChildren()) do
    print(v.Name)
    v.Parent = script.Parent
    wait()
end

PlayerAdded is an event that passes the player who join the game. You want to set up your script like this:

game:GetService("Players").PlayerAdded:Connect(function(player)
   local userId = player.UserId
end)
4 Likes
game.Players.PlayerAdded:connect(function(plr)
     print(plr.UserId)
end)

Thanks it worked! But I have one other question the hats on the npc are slightly off how would i fix this?

I believe that’s an issue with the accessory itself. You could try to manually fix it in the code but that’ll be hard if you don’t know how to. (I don’t mess with accessory cframe positions)

1 Like

ok well thanks anyway! It doesnt really matter