local brick = game.workspace.brick local w = game.workspace:WaitForChild("Player") local h = w.Humanoid local animation = script.Parent:WaitForChild("Animation") local anim = h:LoadAnimation("animation") if brick.BrickColor == BrickColor.Red() then anim:Play() 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
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
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.