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

Failure in ChangeColor Script?

Asked by 4 years ago

Im making a magic crystal, that when the game reaches a determined hour, the color of the crystal will change, i made a script with my small knowledges about scripting for do it, but seems that is a failure in it.

Here is the code that the crystal uses


if game.Lighting.ClockTime == ("6.12") then script.parent.BrickColor.new = ("Really Blue") end if game.Lighting.TimeOfDay == ("06:06:00") then script.parent.BrickColor.new = ("Deep Orange") end
0
you have to do a loop because scripts run once Ashton011 30 — 4y
0
with a While True Do? NerfLambdaWarrior120 3 — 4y
0
well if you use while true do when its not true then it will just end im pretty sure. I really don't know I havent researched loops much though. Ashton011 30 — 4y
0
also i would recommend tweening the color, that would add a nice effect. Ashton011 30 — 4y
0
how i do it? NerfLambdaWarrior120 3 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

You need to be constantly checking. Do:

while true do
    if game.Lighting.ClockTime == ("6.12") then
        script.parent.BrickColor.new = ("Really Blue")
    end

    if game.Lighting.TimeOfDay == ("06:06:00") then
        script.parent.BrickColor.new = ("Deep Orange")
    end
    wait()
end
0
You could just use 'while wait() do' and remove line 9. It works the same way but it makes your script shorter IAmNotTheReal_MePipe 418 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

When changing the brick color of a part, you have to do something like this: part.BrickColor = BrickColor.new("Really Blue")

So an easy fix to your script is to change the "script.Parent.BrickColor.new =" to script.Parent.BrickColor = BrickColor.new("Color")

Furthermore, brickcolors are case-sensitive. You wrote "Really Blue". This has to be written as "Really blue" - with lowercase "b". Same with "Deep Orange" --> "Deep orange"

if game.Lighting.ClockTime == ("6.12") then
    script.parent.BrickColor = BrickColor.new("Really blue")
end

if game.Lighting.TimeOfDay == ("06:06:00") then
    script.parent.BrickColor = BrickColor.new("Deep orange")
end

But this check only runs once, which means you need some kind of loop to constantly check the ClockTime and TimeOfDay. You could use :GetPropertyChangedSignal() to do a check every time "TimeOfDay" or "ClockTime" changes, or you could make a while loop to constantly check these properties.

I believe that's all. If you got any questions or suggestions on improvements I can make, feel free to comment on this answer. (:

Happy scripting!

~Sethex, aka. TheWaterFoox

Answer this question