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

Brick color changing script not working?

local part = script.Parent 
part.BrickColor = BrickColor.new("Institutional white") 

while true do
    wait(0.1)
    local timeoday = game.Lighting.ClockTime 
    if timeoday > 17.6 or timeoday < 6.4 then
      part.Color = BrickColor.new("Institutional white")  

    else
      part.Color = BrickColor.new("Really black")  
end

So here I want to make a brick color change when it's between 17.6 and 6.4. BUt it refuses to work. Why is tha?

2 answers

The problem here is you are using 'or' instead of 'and' in your if statement.

Right now, the if statement is basically checking if it's higher than 17.6 or lower than 6.4.

If you want to check between the times, also do note a better way to do this is to use :GetMinutesAfterMidnight().

local part = script.Parent
part.BrickColor = BrickColor.new("Institutional white")

while true do
	wait(.1)
	if game.Lightning:GetMinutesAfterMidnight() > 17.6 * 60 and game.Lightning:GetMinutesAfterMidnight() > 6.4* 60 then
		part.Color = BrickColor.new("Institutional white")
	else
		part.Color = BrickColor.new("Really black") 
	end
end

4 comments

0

You can also use your method, but you are also missing and end for your if statement.

0

Thanks but I am getting this output error

0

18:41:32.935 - Lightning is not a valid member of DataModel

0

That is odd, maybe try using a variable for lightning. Such as: local Lightning = game:GetService('Lightning').

Old question, but in case anyone comes across this...

Your output window should be showing an error something like:

"invalid argument #3 (Color3 expected, got BrickColor)"

because part.Color needs a Color3 data type, but BrickColor.new returns a BrickColor data type.

To fix this, you need to grab the '.Color' property out of the BrickColor, so it should look like this:

part.Color = BrickColor.new("Really black").Color

Then you're assigning a Color3 to a Color3.

(Also, in the cloud9josh response above, the problem is people keep saying Light-NING when it should be Light-ING).

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