Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Simple script not working, Help?

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

2 comments

0

What do you want this to do though?.. :p

0

There should be a line under the error that tells you where exactly you went wrong.

2 answers

✓ Accepted answer

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.

3 comments

0

I asked the question because I don't know what it means.

0

When you run the game, there should be a blue line just under the error. It will tell you where that error is. Post it.

0

There is no blue line under anywhere, I don't know because I clicked this thing on roblox studio and I think it messed it up :/

This discussion is preserved as it was. New answers, comments, and votes are closed.