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

(SOLVED!) How do you make an Outer Space script once you get to a certain height?

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?

5 comments

0

second one works but it crashes your game

0

actually it game script timeouts but whatever same thing you'll probably close your roblox out before you notice roblox times out for you

0

oh yeah, I forgot to say that I put while wait() do, not while true do.

0

You're not actually doing anything if the Y value is more than 1,000, you're just setting the TimeOfDay to itself. If you want to to become darker, do game.Lighting.TimeOfDay = "22:00:00" or some other hour that is dark.

0

Oh my gosh sorry, I forgot to put something else in. I deleted the script so I can't copy and paste. I actually did "24:00:00".

1 answer

✓ Accepted answer

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.

2 comments

0

I just found out the problem. it was supposed to be >=, not <=. Thanks!

0

If you flip the operator <= in my code, then you'll have to flip 12:00:00 and 24:00:00, otherwise it will be 24:00:00 on the ground and 12:00:00 in space. You can just leave my code as it is, and it works just fine.

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