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

Failure in ChangeColor Script?

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

5 comments

0

you have to do a loop because scripts run once

0

with a While True Do?

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.

0

also i would recommend tweening the color, that would add a nice effect.

0

how i do it?

2 answers

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

1 comment

0

You could just use 'while wait() do' and remove line 9. It works the same way but it makes your script shorter

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

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