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

This is supposed to pick a random skybox, but it's not working and the output isn't helping?

Asked by 7 years ago
Edited 7 years ago
skies = {
"s1",
"s2",
"s3"}
while true do
    csky = math.random(1, #skies)
    wait(0.001)
    if game.Lighting:GetMinutesAfterMidnight() == 0 then
        if skies[csky] == "s1" then
            game.Lighting.Sky.SkyboxBk = "rbxassetid://558861298"
            game.Lighting.Sky.SkyboxDn = "rbxassetid://558860805"
            game.Lighting.Sky.SkyboxFt = "rbxassetid://558861465"
            game.Lighting.Sky.SkyboxLf = "rbxassetid://558860596"
            game.Lighting.Sky.SkyboxRt = "rbxassetid://558861057"
            game.Lighting.Sky.SkyboxUp = "rbxassetid://558861628"
            print("sky1")
        elseif skies[csky] == "s2" then
            game.Lighting.Sky.SkyboxBk = "rbxassetid://510033734"
            game.Lighting.Sky.SkyboxDn = "rbxassetid://510033548"
            game.Lighting.Sky.SkyboxFt = "rbxassetid://510033858"
            game.Lighting.Sky.SkyboxLf = "rbxassetid://510033352"
            game.Lighting.Sky.SkyboxRt = "rbxassetid://510033651"
            game.Lighting.Sky.SkyboxUp = "rbxassetid://510033905"
            print("sky2")
        elseif skies[csky] == "s3" then
            game.Lighting.Sky.SkyboxBk = "rbxassetid://509678983"
            game.Lighting.Sky.SkyboxDn = "rbxassetid://509678855"
            game.Lighting.Sky.SkyboxFt = "rbxassetid://509679034"
            game.Lighting.Sky.SkyboxLf = "rbxassetid://509678765"
            game.Lighting.Sky.SkyboxRt = "rbxassetid://509678922"
            game.Lighting.Sky.SkyboxUp = "rbxassetid://509679076"
            print("sky3")
        end
    end
end

Edit: I forgot to mention, the script is in game.Lighting.Sky

1 answer

Log in to vote
0
Answered by 7 years ago

Hmm, I think the problem is that it's just missing the point where MinutesAfterMidnight is 0. I'm not 100% sure, but try this:

--Assuming that this is a Server script (which it hopefully is)
skies = {
"s1",
"s2",
"s3"}
game.Lighting.LightingChanged:connect(function()
      if game.Lighting:GetMinutesAfterMidnight() == 0 then
            csky = math.random(1, #skies)
                if skies[csky] == "s1" then
                    game.Lighting.Sky.SkyboxBk = "rbxassetid://558861298"
                    game.Lighting.Sky.SkyboxDn = "rbxassetid://558860805"
                    game.Lighting.Sky.SkyboxFt = "rbxassetid://558861465"
                    game.Lighting.Sky.SkyboxLf = "rbxassetid://558860596"
                    game.Lighting.Sky.SkyboxRt = "rbxassetid://558861057"
                    game.Lighting.Sky.SkyboxUp = "rbxassetid://558861628"
                    print("sky1")
                elseif skies[csky] == "s2" then
                    game.Lighting.Sky.SkyboxBk = "rbxassetid://510033734"
                    game.Lighting.Sky.SkyboxDn = "rbxassetid://510033548"
                    game.Lighting.Sky.SkyboxFt = "rbxassetid://510033858"
                    game.Lighting.Sky.SkyboxLf = "rbxassetid://510033352"
                    game.Lighting.Sky.SkyboxRt = "rbxassetid://510033651"
                    game.Lighting.Sky.SkyboxUp = "rbxassetid://510033905"
                    print("sky2")
                elseif skies[csky] == "s3" then
                    game.Lighting.Sky.SkyboxBk = "rbxassetid://509678983"
                    game.Lighting.Sky.SkyboxDn = "rbxassetid://509678855"
                    game.Lighting.Sky.SkyboxFt = "rbxassetid://509679034"
                    game.Lighting.Sky.SkyboxLf = "rbxassetid://509678765"
                    game.Lighting.Sky.SkyboxRt = "rbxassetid://509678922"
                    game.Lighting.Sky.SkyboxUp = "rbxassetid://509679076"
                    print("sky3")
        end
    end
end

Lighting has an event which fires every time a property of game.Lighting is changed. As I said, I'm not completely sure it will work, as I personally haven't done much work when it comes to lighting, but try it nonetheless. :)

0
also I might wanna add that if you have some sort of day/night script, make sure at some point of time it actually hits 00:00:00 (aka GetMinutesAfterMidnight() returns 0) because if it hits like 00:01 then 00:03 this might not work. Pengdoo 26 — 7y
Ad

Answer this question