Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What does "Unable to cast object to int64" mean?

I'm making a game where you can insert models, however it doesn't work. I receive an error saying "Unable to cast object to int64". Help?

MODEL MESSAGER:

local GUI = script.Parent
local Model_ID = GUI:WaitForChild("TextBox")
local Model_Executor = GUI.TextButton

Model_Executor.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.CreateModel:FireServer(Model_ID.Text)
end)

EVENT HANDLER SCRIPT:

game.ReplicatedStorage.CreateModel.OnServerEvent:Connect(function(ID)
	game:GetService("InsertService"):LoadAsset(ID):GetChildren()[1].Parent = workspace
end)

1 answer

✓ Accepted answer

###Yore getting this error because the very first parameter to OnServerEvent is the player that fired the remote. To fix your problem, add a player parameter to the beginning of your OnServerEvent, but do not include it on FireServer. Also, the argument to InsertService:LoadAsset() is an int64, and you're passing a string. You'll want to tonumber the Text. However, since any text can be inputted into TextBoxes, you'll want to wrap the code in a pcall (protected call) so it doesn't error in the output and continue script execution.

local createModel = game.ReplicatedStorage.CreateModel

createModelOnServerEvent:Connect(function(player, ID) -- here
    game:GetService("InsertService"):LoadAsset(ID):GetChildren()[1].Parent = workspace
end)

###local script:

local GUI = script.Parent
local Model_ID = GUI:WaitForChild("TextBox")
local Model_Executor = GUI.TextButton

Model_Executor.MouseButton1Click:Connect(function()
    local success, message = pcall(function()
        local id = tonumber(Model_ID.Text)
        game.ReplicatedStorage.CreateModel:FireServer(id)
    end)
end)

1 comment

0

Thanks Incapaz!

This discussion is preserved as it was. New answers, comments, and votes are closed.