I'm new to coroutines.
local switch_scene= coroutine.wrap(function()
for h,f in pairs(game.Lighting:GetChildren()) do
f:remove()
end
local color=nil
local trans=0
scene=scenary[math.random(1,#scenary)]:Clone()
if scene.Name=="Default" then
color="White"
trans=0.6
end
if scene.Name=="Earth" then
color="Institutional White"
trans=0.8
end
if scene.Name=="Moon" then
color="Deep blue"
trans=0.6
end
if scene.Name=="Nebula" then
color="Dark green"
trans=0.6
end
if scene.Name=="Ocean" then
color="Black"
trans=0.6
end
if scene.Name=="Serenity" then
color="Cyan"
trans=0.8
end
if scene.Name=="Sky blue" then
color="Cyan"
trans=0.8
end
if scene.Name=="Stormy Seas" then
color="Brown"
trans=0.6
end
if scene.Name=="Sunset" then
color="Deep orange"
trans=0.6
end
if scene.Name=="Underworld" then
color="Really red"
trans=0.6
end
for i,v in pairs(windows) do
for i=1,100,-1 do
wait(0.1)
v.Transparency=i/100
end
v.BrickColor=BrickColor.new(color)
scene.Parent=game.Lighting
end
wait(2)
for i,v in pairs(windows) do
for i=1,100 do
wait(0.1)
v.Transparency=i/100
if i==60 then break end
end end
end)
---How can I keep running that at specific times without it dying |