Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Gear giving gui is not working and displays 'Unable to cast string to int64' in output. Why?

Asked by 4 years ago

So I've been trying to make a gear gui where the play can put in an ID from the gear catalog to give them the gear they want. The problem is that whenever said player attempts to put in an ID, the output displays 'Unable to cast string to int64', and will not spawn in that item.

wait(1)
script.Parent.TextButton.MouseButton1Click:Connect(function()
    local insertservice = game:GetService("InsertService")
    local item = insertservice:LoadAsset(script.Parent.TextBox.Text)
    item.Parent = workspace
end)

Any suggestions, tips, or explanations as to why my script isn't working is greatly appreciated!

0
Is this suposed to give the player gear based on a id? If so try using this: tonumber("text here") marine5575 359 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Hello. The problem is that when getting text from a TextBox, the text is a string, not an Int64. To fix this, use the tonumber() global.

wait(1)
script.Parent.TextButton.MouseButton1Click:Connect(function()
    local insertservice = game:GetService("InsertService")
    local item = insertservice:LoadAsset(tonumber(script.Parent.TextBox.Text))
    item.Parent = workspace
end)
0
Hello! Thanks for the tip, but when running the script again, the output is now saying "Argument 1 missing or nil". littlekit07 16 — 4y
0
Is it a LocalScript? If it isn't then use a LocalScript and set "AllowClientInsertModels" to true. youtubemasterWOW 2741 — 4y
Ad

Answer this question