Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Simple script not working, Help?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
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

0
What do you want this to do though?.. :p lucas4114 607 — 9y
0
There should be a line under the error that tells you where exactly you went wrong. funyun 958 — 9y

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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!

Ad
Log in to vote
0
Answered by 9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

There is a detailed description of what went wrong in the output: it gives you what's incorrect and the line it's on.

0
I asked the question because I don't know what it means. salmonbear242 50 — 9y
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. funyun 958 — 9y
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 :/ salmonbear242 50 — 9y

Answer this question