Hello,
I am making a script so that when the player's torso y position is > 1500, the sky turns to night time. I'm pretty sure the problem is that i'm trying to make it happen to only one player. When I run the game, the sky turns very bright neon white which is not what happens when I manually change the lighting.
Here is my code, written in a LocalScript located in StarterCharacterScripts:
local character = script.Parent local Atmosphere = game.Lighting.Atmosphere local Lighting = game.Lighting while true do local pos = character.UpperTorso.Position.Y if pos > 1500 then Atmosphere.Color = Color3.new(40,40,40) Lighting.TimeOfDay = "24:00:00" else Atmosphere.Color = Color3.new(250,250,250) Lighting.TimeOfDay = "15:00:00" end wait(2) end
Thank you again!
The code has a common problem with Color3 values: the constructor expects variables between 0 and 1, not 0 and 255. The fix is to divide everything by 255:
local character = script.Parent local Atmosphere = game.Lighting.Atmosphere local Lighting = game.Lighting while true do local pos = character.UpperTorso.Position.Y if pos > 1500 then Atmosphere.Color = Color3.new(40/255,40/255,40/255) Lighting.TimeOfDay = "24:00:00" else Atmosphere.Color = Color3.new(250/255,250/255,250/255) Lighting.TimeOfDay = "15:00:00" end wait(2) end