'Unable to cast Instance to int64' Using remote events, Userid

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!

wait so the text is = to the player name?

user would need to be the player who focused on the text

Heyo!

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.

3 Likes

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.

ohhhh, makes alot more sense, let me think for a seconds…

did you get “Players” Service

you need to type

local Players = game:GetService("Players") --Gets "Players" Service

--and the userid would be:
local userid = Players:GetUserIdFromUsername(user)

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 should work, I did this a while ago when making a cross server chatting system!

okay, i will replace the local function with this and see if it does the same and / or fixes the issue

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)

did you describe Players?

Players need to be game:GetSevice(“Players”)

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)

ohhh, try userid.Name, or userid.Value I’ve had this problem as well lol

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

for your server use this

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!

1 Like

thank you! the other error was in my localscript i had userId:FireServer(Players, userid) which gave the Instance error, it works now!