I am trying to run an animation in an NPC but I keep getting the same error, this is my code:
Wizard = {game.Workspace.ClassChoose.WizardSet.WizardDummy, 7, 15}
function Choose(Class)
if Class == "Mage" then
local animController = Instance.new("AnimationController")
animController.Parent = Wizard[1]
local animTrack = animController:LoadAnimation("http://www.roblox.com/Asset?ID=371493384")
animTrack:Play()
Wizard[1].Tome.Book.Transparency = 0
Wizard[1].Tome.Pages.Transparency = 0
for i = 1, 10 do
local Magic = game.Lighting.Magic:Clone()
Magic.Position = CFrame.new(Wizard[0]["Left Arm"].Position + (math.random(5, 10)/100))
end
end
end
Choose("Mage")
Why does this return this error:
23:02:36.087 - Unable to cast value to Object
23:02:36.087 - Script 'Players.Player.PlayerGui.LocalScript', Line 7 - global Choose
23:02:36.088 - Script 'Players.Player.PlayerGui.LocalScript', Line 19
23:02:36.088 - Stack End
Finally; I have used the array correctly, for some reason the array now counts from 1 in the first place not 0. Thanks.
EDIT: With what you have said lines 4-6 have been changed to:
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/Asset?ID=371493384"
local animController = Instance.new("AnimationController")
local animTrack = animController:LoadAnimation(anim)
anim.Parent = Classes[Class][1]
animTrack:Play()
But I am getting the same error.

1 comment
Arrays in Lua are 1-indexed, not 0-indexed like in other languages. The first element of an array starts at [1], not [0].