1 | local brick = game.workspace.brick |
2 | local w = game.workspace:WaitForChild( "Player" ) |
3 | local h = w.Humanoid |
4 | local animation = script.Parent:WaitForChild( "Animation" ) |
5 | local anim = h:LoadAnimation( "animation" ) |
6 | if brick.BrickColor = = BrickColor.Red() then |
7 | anim:Play() |
8 | end |
Output = 20:49:39.672 - Unable to cast value to Object
Unable to cast value to Object
"Cast" means "convert". This error means something on this line
1 | local anim = h:LoadAnimation( "animation" ) |
couldn't convert something into an object.
The only thing that isn't an object in that line is "animation"
-- which it's not, it's text.
The LoadAnimation
method needs an animation object -- not text. The correct line is
1 | local anim = h:LoadAnimation( animation ) |
you have to give it the value you already defined on line 4!
There is a detailed description of what went wrong in the output: it gives you what's incorrect and the line it's on.