In a localscript I have a local function that takes the username entered and gets the userid, and returns it as
local userid = getUserIdFromUsername(user)
I used this to have an ImageLabel of the users’ avatar headshot which worked, but what I am currently trying to do is use a RemoteEvent to pass the userid given to a regular script, and apply a humanoid description using the id. I’m fairly new to using RemoteEvents and the confusing part is that the userid local was able to be used to make the headshot, but not to apply a description. I believe it is because GetHumanoidDescriptionFromUserId() uses a string value, but the value passed through the RemoteEvent is an Instance. Is there any way I can have the id inside GetHumanoidDescriptionFromUserId() the userid given in the localscript?
Code for reference:
Localscript (not full script)
local user = script.Parent.Parent:FindFirstChild("InputBox").Text -- username input
local userid = getUserIdFromUsername(user) -- function to get the userid
userId:FireServer(userid)
Script
game.ReplicatedStorage.UserId.OnServerEvent:Connect(function(userid)
local d = game.ServerStorage.BaseAvatar:Clone() -- avatar used
local desc2 = game.Players:GetHumanoidDescriptionFromUserId(userid) -- getting the current avatar
d.Parent = workspace.Map
d.Humanoid:ApplyDescription(desc2)
end)
Again, I am fairly new at using RemoteEvents and scripting in general, and after searching around for a while I still couldn’t figure out the solution. Sorry if I made it sound more complicated than it really is, thanks!
Check your OnServerEvent function RemoteEvent | Roblox Creator Documentation - it takes in a Player object first, and then any other argument (information) you pass in after, such as your userId. Think of it as a list.
a user inputs a username into a textbox, and the local function gets the UserId from the username they entered. i currently want to use a RemoteEvent to pass the UserId given to a regular script so i can load a humanoid with an avatar description from that UserId.
it’s a bit complicated but basically i need to transfer the UserId from the localscript to a script and put it inside GetHumanoidDescriptionFromUserId(), but it requires a string from what i know.
would this still be retrieving the UserId from the text entered in the TextBox? what i was doing before was using a local function to get the UserId from the text entered, i’m not sure if it was needed. it used the player service as well
it returns the error 'GetUserIdFromUsername is not a valid member of Players “Players”
i’m not completely sure but the text entered in the TextBox is any username on the platform currently existing, not just in servers. i don’t know if that makes a difference
code:
local user = script.Parent.Parent:FindFirstChild("InputBox").Text -- could be anything, only actually works if it's a valid username past this
local userid = Players:GetUserIdFromUsername(user)
yes, i think the core issue is GetHumanoidDescriptionFromUserId() requires a string and i’m giving it an instance, i can get the userid but i’m assuming it is an Instance as the error would say
i don’t know if there is a way to use my current method still or try to find a different method of getting the UserId and passing it through a RemoteEvent while still having it be a string
game.ReplicatedStorage.UserId.OnServerEvent:Connect(function(Players, userid)
local d = game.ServerStorage.BaseAvatar:Clone()
local desc2 = game.Players:GetHumanoidDescriptionFromUserId(userid)
userid.Name returns ‘unable to cast string to int64’, value returns an error regarding Players
edit: int64 is a number value, so they are expecting ‘239873’ as an example. i don’t know how to convert the userid value to a number in the script though, because that is what it wants
game.ReplicatedStorage.UserId.OnServerEvent:Connect(function(plr,userid)
local d = game.ServerStorage.BaseAvatar:Clone() -- avatar used
local desc2 = game.Players:GetHumanoidDescriptionFromUserId(userid) -- getting the current avatar
d.Parent = workspace.Map
d.Humanoid:ApplyDescription(desc2)
end)
the reason your code wasnt working because the first parameter you get would always be the player,dont forget that!