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

"Unable to cast value to Object" error while tweening an object's color, what's wrong?

Asked by 3 years ago

Here is my script, it's a server script.

01local PcOn = script.Parent
02 
03local rgb = PcOn.Parent.Parent.Case.rgbCables:GetChildren() -- rgb part
04 
05local colors = {BrickColor.new("Steel blue").Color,
06    BrickColor.new("Bright violet").Color,
07    BrickColor.new("Magenta").Color,
08    BrickColor.new("Neon orange").Color,
09    BrickColor.new("Bright yellow").Color,
10    BrickColor.new("Lime green").Color,
11    BrickColor.new("Toothpaste").Color}
12 
13local tweenService = game:GetService("TweenService")
14 
15rgb.Material = ("Neon")
View all 38 lines...

It used to work but when I added the "while" loop at the end, it suddenly stopped working, even though I need the while loop to check the value of the BoolValue instance.

I get this error when the script runs:

21:40:33.919 Unable to cast value to Object - Server - RgbOn:24

21:40:33.919 Stack Begin - Studio

21:40:33.919 Script 'Workspace.PC.Motherboard.IsPcOn.RgbOn', Line 24 - function ColorChange - Studio - RgbOn:35

21:40:33.920 Script 'Workspace.PC.Motherboard.IsPcOn.RgbOn', Line 34 - Studio RgbOn:45

21:40:33.920 Stack End

All help is appreciated.

0
I don't know if this has anything to do with the problem, but the while loop is inefficient. A better way to do this would be to check if the PcOn changed.https://dpaste.org/BxHP mariohead13 129 — 3y
0
@mariohead13 you can do :GetPropertyChangedSignal("Value") MarkedTomato 810 — 3y
0
This errors because your tweening an array, you can't do that. MarkedTomato 810 — 3y
0
You could do; for index, value in ipairs(rgb) do; tweenService:Create(value,tweenInformation,ColorProperty):Play() MarkedTomato 810 — 3y
0
You should destroy tweens once they are of no further use; this prevents memory leaks. appxritixn 2235 — 3y

Answer this question