Basically, what my code is trying to do is when the user types in a userid into the Textbox, the humanoid applies the description of the userid that was typed into the textbox.
This howevery isnt working and I get this error:
Error: "Unable to cast string to int64"
This is my code:
local humanoid = script.Parent.Humanoid
local textbox = game.StarterGui.Main.MainFrame.UsernameIdPicker
humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(textbox.Text))
I am a little new so any easy steps to fix this are appreciated, thank you
local humanoid = script.Parent.Humanoid
local textbox = game.StarterGui.Main.MainFrame.UsernameIdPicker
if tonumber(textbox.Text) then
humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(tonumber(textbox.Text)))
end
unfortunately, that didn’t work. But for some reason when I change the text on the TextBox, the text in the Text property doesn’t change, although even when i set the Text property to a value it still won’t work, sorry.
Ah, in this case it would be a little more complex.
You would have to fire a RemoteEvent to the server, in which takes in the text value and applies the description. This is because a Server Script cannot access the player’s UI.
local humanoid = game.Workspace.Dummy.Humanoid
local replicatedstorage = game:GetService("ReplicatedStorage")
local playergui = game.Players.LocalPlayer.PlayerGui
local textbox = playergui.Main.MainFrame.UsernameIdPicker
if tonumber(textbox.Text) then
replicatedstorage.CharacterChooser:FireServer()
end
I’m just a little confused on how I should write the code that needs to be fired if I stil have to access playergui with a client script
local humanoid = game.Workspace.Dummy.Humanoid
local replicatedstorage = game:GetService("ReplicatedStorage")
local playergui = game.Players.LocalPlayer.PlayerGui
local textbox = playergui.Main.MainFrame.UsernameIdPicker
if tonumber(textbox.Text) then
replicatedstorage.CharacterChooser:FireServer(tonumber(textbox.Text))
end
Server:
local replicatedstorage = game:GetService("ReplicatedStorage")
replicatedstorage.CharacterChooser.OnServerEvent:connect(function(id)
humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(id))
end)
Still doesnt work. Thank you for the help. Sorry for making you do all this work. I can figure it out from here but you are good if you don’t want to help anymore. Thanks again!
Put this in start the UsernameIDPicker as a LocalScript
local humanoid = game.Workspace.Dummy.Humanoid
local replicatedstorage = game:GetService("ReplicatedStorage")
local playergui = game.Players.LocalPlayer.PlayerGui
local textbox = script.Parent
if tonumber(textbox.Text) then
replicatedstorage.CharacterChooser:FireServer(tonumber(textbox.Text))
end
Put this in ServerScriptService and a normal Script.
local replicatedstorage = game:GetService("ReplicatedStorage")
replicatedstorage.CharacterChooser.OnServerEvent:connect(function(id)
humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(id))
end)
seems like its not getting recieved. what does the (plr,id) part mean? how does it help make the UserId in the textlable give those properties to the dummy?
local replicatedstorage = game:GetService("ReplicatedStorage")
replicatedstorage.CharacterChooser.OnServerEvent:connect(function(plr,id)
print(plr,id)
game.Workspace.Dummy.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(id))
end)
Tryin’ to get the text from the “UserNameIdPicker” through a server script wont work since when you’re interacting with anythin’ on the client such as a textbox. Nothin’ replicates to the server. Everythin’ is local to you.
To combat this try parenting your local script into the “StarterPlayerScripts” instead and type the following:
local Plr = game.Players.LocalPlayer
local textbox = Plr.PlayerGui:WaitForChild("Main").UserNameIdPicker
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
textbox.FocusLost:Connect(function(Send: boolean)
if Send and tonumber(textbox.Text) then -- // Make sure we pressed "Enter" and the text is a number.
Event:FireServer(tonumber(textbox.Text))
end
end)
Now to actually apply the description to the dummy on the server. You’ll need to have a server script inside “ServerScriptService” to listen for when it gets triggered by the client
local Remote = game.ReplicatedStorage.RemoteEvent
local Dummy = game.Workspace.Dummy -- // Refrence your path to your dummy here. Mines workspace.
Remote.OnServerEvent:Connect(function(Player: Player, UserId: number) -- // Player is the player who triggered the remote(OPTIONAL), Second is the arg you sent over.
local Desc = game.Players:GetHumanoidDescriptionFromUserId(UserId)
Dummy.Humanoid:ApplyDescription(Desc)
end)