Skybox system help

Can someone fix this code, it’s not working.

local function createSkybox(moonTextureId, sunTextureId, bk, dn, ft, lf, rt, up)
	local sky = Instance.new("Sky")
	sky.MoonTextureId = moonTextureId
	sky.SunTextureId = sunTextureId
	sky.SkyboxBk = bk
	sky.SkyboxDn = dn
	sky.SkyboxFt = ft
	sky.SkyboxLf = lf
	sky.SkyboxRt = rt
	sky.SkyboxUp = up
	return sky
end

local morningSky = createSkybox(
	"rbxassetid://4547507884",
	"rbxassetid://6196665106",
	"rbxassetid://6444884337",
	"rbxassetid://6444884785",
	"rbxassetid://6444884337",
	"rbxassetid://6444884337",
	"rbxassetid://6444884337",
	"rbxassetid://6412503613"
)

local eveningSky = createSkybox(
	"rbxassetid://4547507884",
	"rbxassetid://6196665106",
	"rbxassetid://16136021536",
	"rbxassetid://16136025360",
	"rbxassetid://16136021536",
	"rbxassetid://16136021536",
	"rbxassetid://16136021536",
	"rbxassetid://16136023362"
)

local nightSky = createSkybox(
	"rbxassetid://4547507884",
	"rbxassetid://6196665106",
	"rbxassetid://15536110634",
	"rbxassetid://15536112543",
	"rbxassetid://15536116141",
	"rbxassetid://15536114370",
	"rbxassetid://15536118762",
	"rbxassetid://15536117282"
)

local Lighting = game:GetService("Lighting")

local function updateSky()
	local currentTime = Lighting.TimeOfDay
	local hour = tonumber(string.sub(currentTime, 1, 2))
	if hour >= 6 and hour < 12 then
		-- Morning
		Lighting.Sky = morningSky
		Lighting.Brightness = 2
		Lighting.Ambient = Color3.fromRGB(255, 255, 255)
		Lighting.OutdoorAmbient = Color3.fromRGB(200, 200, 200)
	elseif hour >= 18 and hour < 20 then
		Lighting.Sky = eveningSky
		Lighting.Brightness = 1.5
		Lighting.Ambient = Color3.fromRGB(255, 150, 100)
		Lighting.OutdoorAmbient = Color3.fromRGB(179, 119, 60)
	else
		Lighting.Sky = nightSky
		Lighting.Brightness = 0.5
		Lighting.Ambient = Color3.fromRGB(6, 6, 13)
		Lighting.OutdoorAmbient = Color3.fromRGB(12, 12, 24)
	end
end

updateSky()

while true do
	updateSky()
	wait(60)
end

The script is in ServerScriptService and all the skies are in ServerStorage in a folder named “Sky”

1 Like

Are you parenting the Sky to Lightning?

2 Likes

No, as I have mentioned the texture ID

Sky isn’t a property of Lightning. It’s a child, so you have to parent it instead or change the objects id’s

2 Likes

2 Likes

I tried it but it just randomly shows the sky, not according to what I want.
I want like-
When the time is 6-18 then morningSky comes
then from 18-20 eveningSky comes
then 20-6 nightSky comes
but it doesn’t work like that. It just generates one of the sky from the Lightning

1 Like

why not create sky and place them inside server storage then, clone them and destroy them when the hours reached

1 Like

Skies are already in server storage

local currentSky = Lightning.Sky
if hour >= 6 then
    local sky = createSkybox()
    sky.Parent = Lightning
    currentSky:Destroy()
end

heres an example

1 Like

Not changing

This is Morning Sky

This is Evening Sky

This is Night Sky

Skies in ServerStorage
image

Script in ServerScriptStorage (script name-Sky)
image

You’re calling update sky every 60 seconds.

1 Like

It is for the check of the game time

thank you it is working now, i did some error before but now its working

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.