Im trying to make a script when an user enters someones user’s ID, it loads their avatar.
How it works is the user enters an ID on a textbox, puts that ID into a StringValue, and code does it’s thing.
But i get the error Unable to cast string to int64.
What im trying to make is a meme game. I’ve looked at posts multiple times and I still haven’t found an issue, please help.
Textbox code:
local id = script.Parent.Parent.FirstID.Text
local plr = game.Players
local event = game.ReplicatedStorage.LoadPlayer1
local button = script.Parent.Parent.FirstApply
local firstguymodel = workspace.FirstGuy
button.MouseButton1Click:Connect(function()
wait(1)
event:FireServer()
firstguymodel:WaitForChild("Id").Value = tostring(id)
end)
Applying the avatar code:
local model = script.Parent
local humanoid = model:WaitForChild("Humanoid")
local event = game.ReplicatedStorage.LoadPlayer1
local ID = script.Parent.Id.Value
event.OnServerEvent:Connect(function()
wait(1)
local description = game:GetService("Players"):GetHumanoidDescriptionFromUserId(ID)
humanoid:ApplyDescription(description)
end)
ID needs to be a number not a string. Convert it to a number by using the tonumber function as shown below
Change Applying the avatar code to this:
local model = script.Parent
local humanoid = model:WaitForChild("Humanoid")
local event = game.ReplicatedStorage.LoadPlayer1
local ID = script.Parent.Id.Value
event.OnServerEvent:Connect(function()
wait(1)
local description = game:GetService("Players"):GetHumanoidDescriptionFromUserId(tonumber(ID))
humanoid:ApplyDescription(description)
end)
It’s because you are changing the ID value on the client and trying to access it on the server.
Change your Textbox code to this:
local id = script.Parent.Parent.FirstID.Text
local plr = game.Players
local event = game.ReplicatedStorage.LoadPlayer1
local button = script.Parent.Parent.FirstApply
local firstguymodel = workspace.FirstGuy
button.MouseButton1Click:Connect(function()
wait(1)
event:FireServer(id)
firstguymodel:WaitForChild("Id").Value = tostring(id)
end)
Change your avatar code to this:
local model = script.Parent
local humanoid = model:WaitForChild("Humanoid")
local event = game.ReplicatedStorage.LoadPlayer1
local ID = script.Parent.Id.Value
event.OnServerEvent:Connect(function(id)
wait(1)
local description = game:GetService("Players"):GetHumanoidDescriptionFromUserId(tonumber(id))
humanoid:ApplyDescription(description)
end)
It’s because when we fire to the server, we fired the variable that we define outside of the MouseButton1Click callback, we don’t need to find the variable and can just fire it in the RBXScriptConnection as shown below.
Try this then
Textbox code:
local Players = game:GetService("LocalPlayer")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local localPlayer = Players.LocalPlayer :: LocalPlayer
local loadPlayerRemoteEvent = ReplicatedStorage.LoadPlayer1
local firstGuyModel = Workspace:WaitForChild("FirstGuy")
local applyButton = script.Parent.Parent.FirstApply
applyButton.Activated:Connect(function()
task.wait(1)
loadPlayerRemoteEvent:FireServer(script.Parent.Parent.FirstID.Text)
end)
Avatar Code:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local model = script.Parent
local humanoid = model:WaitForChild("Humanoid")
local loadPlayerRemoteEvent = ReplicatedStorage.LoadPlayer1
loadPlayerRemoteEvent.OnServerEvent:Connect(function(id)
task.wait(1)
local description = Players:GetHumanoidDescriptionFromUserId(tonumber(id))
humanoid:ApplyDescription(description)
end)
I don’t see what the problem is, we can use print statements to debug it.
Textbox code:
local Players = game:GetService("LocalPlayer")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local localPlayer = Players.LocalPlayer :: LocalPlayer
local loadPlayerRemoteEvent = ReplicatedStorage.LoadPlayer1
local firstGuyModel = Workspace:WaitForChild("FirstGuy")
local applyButton = script.Parent.Parent.FirstApply
applyButton.Activated:Connect(function()
task.wait(1)
local idText = script.Parent.Parent.FirstID.Text
print("Client", idText)
loadPlayerRemoteEvent:FireServer(script.Parent.Parent.FirstID.Text)
end)
Avatar Code:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local model = script.Parent
local humanoid = model:WaitForChild("Humanoid")
local loadPlayerRemoteEvent = ReplicatedStorage.LoadPlayer1
loadPlayerRemoteEvent.OnServerEvent:Connect(function(id)
task.wait(1)
print("Server", id, humanoid)
local description = Players:GetHumanoidDescriptionFromUserId(tonumber(id))
humanoid:ApplyDescription(description)
end)
local Players = game:GetService("Players")
local model = script.Parent
local humanoid = model:WaitForChild("Humanoid")
local event = game.ReplicatedStorage.LoadPlayer1
local ID = script.Parent.Id.Value
event.OnServerEvent:Connect(function(player, id)
task.wait(1)
local description = Players:GetHumanoidDescriptionFromUserId(tonumber(id))
humanoid:ApplyDescription(description)
end)