I am making a game that includes having people type in a username, and it loads that username's avatar onto a dummy. Here's the following code:
script.Parent.MouseButton1Click:Connect(function() local PlrName = game.Players:GetUserIdFromNameAsync(script.Parent.Parent.NameBox.Text) local Guy = game.Players:CreateHumanoidModelFromUserId(PlrName) game.Workspace.Dummy.Head.face.Texture = Guy.Head.face.Texture for i, v in pairs(Guy:GetChildren()) do if v:IsA("Clothing") or v:IsA("BodyColors") or v:IsA("Accessory") then v.Parent = game.Workspace.Dummy end end end)
I also will show the gui it holds:
Whenever I use this, it shows me an error saying that the username is incorrect. I did some digging around, and found out it's only locking the text when you first run the game. I figured this out by making the text a username, for example "ROBLOX" before running the game. And it worked. Anyone have an idea for how to help?
Thanks!
Instead of using MouseButton1Click
, it will fire the function when you click, you do FocusLost
, which will fire when the player stops typing.
You should also consider making a error check when you try to create the humanoid model too because sometimes a player's avatar doesn't exist or one of the player accessory doesn't exist, it will error (I'm not sure)