It's supposed to check every tenth of a second if it's night (18:00:00 thru 6:15:00) and if each part of a model is either Institutional white or New Yeller. It isn't working and there's no output. Please help!
Here's the script:
while wait(0.1) do local Children = script.Parent.ZombieSignA:GetChildren() for i,v in pairs(Children) do if game.Lighting.TimeOfDay >= "18:00:00" or game.Lighting.TimeOfDay <= "6:15:00" and v.BrickColor == "Institutional white" or v.BrickColor == "New Yeller" then v.Material = "Neon" else v.Material = "Plastic" end end end
Thank you in advance for any help you may provide.
TimeOfDay is a string. Therefore, you cannot compare if one is larger than the other, because they are strings, not numbers.
To fix this, you can use the GetMinutesAfterMidnight
method to determine the amount of minutes that has passed after midnight. This method takes no parameters. Midnight is 00:00:00, so 18:00:00 would be 1,080 minutes and 6:15:00 would be 375 minutes.
Also, in your conditional statement, the wrong conditions would be met before the script would continue. Place parentheses around the statements you want to count as a whole.
Fixed Code:
while wait(0.1) do local Children = script.Parent.ZombieSignA:GetChildren() for i,v in pairs(Children) do if (game.Lighting:GetMinutesAfterMidnight() >= 1080 or game.Lighting:GetMinutesAfterMidnight() <= 375) and (v.BrickColor == BrickColor.new("Institutional white") or v.BrickColor == BrickColor.new("New Yeller")) then v.Material = Enum.Material.Neon else v.Material = Enum.Material.Plastic end end end
If I helped you, be sure to accept my answer!
while wait(0.1) do local Children = script.Parent.ZombieSignA:GetChildren() for i,v in pairs(Children) do if game.Lighting:GetMinutesAfterMidnight() >= 1080 or game.Lighting:GetMinutesAfterMidnight() <= 375 and (v.BrickColor == BrickColor.new("Institutional white") or v.BrickColor == BrickColor.new("New Yeller")) then v.Material = "Neon" else v.Material = "Plastic" end end end
You cannot compare TImeOfDay as a number because it is a string. But we could use :GetMinutesAfterMidnight()
. :GetMinutesAfterMidnight()
gets the amount of minutes passed after 24:00:00 or 00:00:00. Obviously, to convert 'TimeOfDay' to ':GetMinutesAfterMidnight()' We will have to convert the hours to minutes. Hence the numbers 1080 and 375.