Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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?

0
second one works but it crashes your game Fifkee 2017 — 4y
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 Fifkee 2017 — 4y
0
oh yeah, I forgot to say that I put while wait() do, not while true do. marioman1932 48 — 4y
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. Unhumanly 152 — 4y
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". marioman1932 48 — 4y

1 answer

Log in to vote
0
Answered by
Unhumanly 152
4 years ago

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.

0
I just found out the problem. it was supposed to be >=, not <=. Thanks! marioman1932 48 — 4y
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. Unhumanly 152 — 4y
Ad

Answer this question