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.

local PcOn = script.Parent

local rgb = PcOn.Parent.Parent.Case.rgbCables:GetChildren() -- rgb part

local colors = {BrickColor.new("Steel blue").Color, 
    BrickColor.new("Bright violet").Color,
    BrickColor.new("Magenta").Color,
    BrickColor.new("Neon orange").Color,
    BrickColor.new("Bright yellow").Color,
    BrickColor.new("Lime green").Color,
    BrickColor.new("Toothpaste").Color} 

local tweenService = game:GetService("TweenService")

rgb.Material = ("Neon")

function ColorChange(colorToChangeTo)

    local tweenInformation = TweenInfo.new(1) -- Time1
    local ColorProperty = {}

    ColorProperty.Color = colorToChangeTo

    local tween = tweenService:Create(rgb,tweenInformation,ColorProperty)
    tween:Play()

    wait(1) -- Time2

end

while true do
    if PcOn.Value == true then
        for i, v in ipairs(colors) do
            ColorChange(v)
        end
    end
    wait()
end

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