I made rocket that you can ride upwards, but I want to make it where you get to a certain height that it looks like you're in space. (I had a day-night script that used values) The script I used is (This is in a local script in Starter Gui)
if game.Workspace.Rocket.Base.Main.Position.Y <= 1000 then game.Lighting.TimeOfDay = "24:00:00" else game.Lighting.TimeOfDay = game.Lighting.TimeOfDay end
It didn't change the Time Of Day, so I tried a while loop
while wait() do if game.Workspace.Rocket.Base.Main.Position.Y <= 1000 then game.Lighting.TimeOfDay = "24:00:00" else game.Lighting.TimeOfDay = game.Lighting.TimeOfDay end end
and this time, the time stayed at 12:00, and it was flashing looking like it was trying to switch the time, and once the rocket got over 1000 height, it stopped flashing. Can somebody give me a working script, or tell me something I did wrong with the current script?
I hope I'm getting this right.
You want to (locally) change the TimeOfDay from 12:00:00 to 24:00:00 in Lighting to make it appear that the Player is in space when they ride the rocket.
while wait() do if game.Workspace.Rocket.Base.Main.Position.Y <= 1000 then game.Lighting.TimeOfDay = "12:00:00" else game.Lighting.TimeOfDay = "24:00:00" end end
Now, this should work just fine, but since I don't know the whole context of this game, I'm going to assume the Player can exit the rocket at any time and fall all the way back down to the ground.
If they're on the ground and the Rocket reaches an altitude of 1,000 studs, the sky will still darken for them, because the LocalScript is looking at the height of the Rocket, not the Player.
If I were you, I'd consider checking the height of the Character's HumanoidRootPart, and not the Rocket.
local Player = game.Players.LocalPlayer local Character = (Player.Character or Player.CharacterAdded:Wait()) local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart') while wait() do if HumanoidRootPart.Position.Y <= 1000 then game.Lighting.TimeOfDay = "12:00:00" else game.Lighting.TimeOfDay = "24:00:00" end end
I hope I helped.