API Wiki is down. What is the error I am having?

So, I have some some simple code. One calls RandomHat, which simply takes the gender of the dummy (used for naming and hat purposes) and then picks a random assetid from a list of id’s that I have compiled. It then returns this. For some reason, the game responds with the error,

"Unable to cast value to Object"

Why, and how can I fix this?

local HatID = RandomHat(dummy.Gender.Value)

This probably means that Humanoid:AddAccessory expects an accessory instance, not an asset id, that welds the accessory provided to the humanoid’s character by finding similarly named attachments in the Handle or elsewhere.

This probably means you have to create the asset from the id using InsertService I believe, specifically using InsertService:LoadAsset or a similarly named method, and then use AddAccessory on the asset returned.

I may be totally wrong though, I haven’t been able to touch studio in a long while.

You can also find explanations of methods of the humanoid in the Class Browser Object Browser I think, accessible via the view ribbon at the top of the studio window.

From using the object browser (not class browser) I did find out it needs an accessory.
However, I do not know what to put in the arguments of LoadAsset. Trying the rbxassetid:// method gets the error

[Unable to cast string to int64]

What I found out on a ScriptingHelpers post after digging a bit more is that I have to remove rbxassetid:// and get the 1st object of the :GetChildren() table. That fixes it.

1 Like