(SOLVED) Can't figure out how to get the current user ID

I’m trying to get a dummy that displays the user in a local script but I can’t figure out how to do it.
So if anyone knows how i can do this it would be alot of help.
So it will show the current players avatar

I’m new to coding so I don’t really know all the little things.

1 Like

I think doing local id = game.players.localplayer.UserId should work

2 Likes

Do this in a LocalScript but remember to respect capital letters, like this:

local Id = game.Players.LocalPlayer.UserId

I recommend giving Humanoid Description a good read.

Example Code

This does go in a Local script.

local player = game.Players.LocalPlayer -- Gets the Local player
local playerModel = game.Players:CreateHumanoidModelFromUserId(player.UserId) -- gets exact player model(R6/R15/RTHO)
playerModel.Parent = workspace -- put model in workspace
2 Likes

Uh the script isn’t working for me. And even if it did spawn i can’t figure out a way to put it in that room

2 Likes

Make a part in the room like a player spawn part. Make sure the Front is facing the Menu Camera.
The model’s RootPart may of needed to be Anchored.
Something as so.

Code
local player = game.Players.LocalPlayer 
local part = -- put the Part here
local playerModel = game.Players:CreateHumanoidModelFromUserId(player.UserId) 
playerModel.PrimaryPart.Anchored = true
playerModel.Parent = workspace
playerModel:PivotTo(part:GetPivot())
Recommendations

Disable Display name on model(also needs to be scripted).

Seat model on chair/play looped animations.

If the model does not spawn in it may be do to network issues or error in the code(check error reports). Best bet is error in the code which I apologize for if so.

[Fixed]

2 Likes

I might be putting the script in the wrong area i think.

It’s Local Script, so it go’s in Starter Player/Character scripts or in StarterGUI

I personally put it in StarterGUI :smiley:

Oh ok, thanks. I’m going to test out the script now.

1 Like

Anchored is not a valid member of player. Is the error message

ah, my mistake, Replace it with

playerModel.PrimaryPart.Anchored = true

If that’s an error, then just remove that line of code.

1 Like

Uh one more thing. Is there anything different I have to do for an animation script compared to normal? Because it seems like it would be harder to play animations on it.

Note, the model is client based and only client scripts can interact with it. So play the animation on the client side.

Load Animation Code(Same as normal)
local animation = script:WaitForChild("Animation") -- replace with your anim
local AnimationTrack:AnimationTrack = playerModel.Humanoid.Animator:LoadAnimation(animation) -- : -- this is a check thing
AnimationTrack:Play() -- play as normal

Hope everything works out for ya, and Have a Blessed Day! :grin:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.