Unable to load char into game through script

So I have been struggling just to load the player’s character into a dummy when a textbox has been focused and typed to the player’s usernaame. How am I able to do this?

There’s quite a few steps involved to achieve this, here’s what worked for me.

--LOCAL

local players = game:GetService"Players"
local getUserIdFromName = players.GetUserIdFromNameAsync
local getHumanoidDescriptionFromUserId = players.GetHumanoidDescriptionFromUserId

local replicated = game:GetService"ReplicatedStorage"
local remote = replicated:WaitForChild"RemoteEvent"

local textbox = script.Parent
local textChanged = textbox:GetPropertyChangedSignal"Text"

local function onTextboxTextChanged()
	textbox.Text = string.gsub(textbox.Text, "[%W_]", "")
	local length = string.len(textbox.Text)
	if length >= 3 and length <= 20 then
		local success, result = pcall(getUserIdFromName, players, textbox.Text)
		if success then
			if result then
				remote:FireServer(result)
			end
		else
			warn(result)
		end
	end
end

textChanged:Connect(onTextboxTextChanged)
--LOCAL

local players = game:GetService"Players"
local getHumanoidDescriptionFromUserId = players.GetHumanoidDescriptionFromUserId
local replicated = game:GetService"ReplicatedStorage"
local remote = replicated.RemoteEvent

local dummy = workspace.Dummy
local humanoid = dummy.Humanoid

local function onRemoteFired(player, userId)
	local success, result = pcall(getHumanoidDescriptionFromUserId, players, userId)
	if success then
		if result then
			humanoid:ApplyDescription(result)
		end
	else
		warn(result)
	end
end

remote.OnServerEvent:Connect(onRemoteFired)

You’ll need an NPC in the workspace container named “Dummy” which contains a humanoid instance, you’ll also need a RemoteEvent instance placed inside the ReplicatedStorage folder.

Place.rbxl (35.0 KB)

1 Like