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

Does this script work and a way to shorten this script?

Asked by
yoshi8080 445 Moderation Voter
9 years ago

I don't think the lights and the parts are changing at the timeofday

light1 = game.Workspace.Streetlights.Light1.LightPart:FindFirstChild("SpotLight")
light2 = game.Workspace.Streetlights.Light2.LightPart:FindFirstChild("SpotLight")
light3 = game.Workspace.Streetlights.Light3.LightPart:FindFirstChild("SpotLight")
light4 = game.Workspace.Streetlights.Light4.LightPart:FindFirstChild("SpotLight")
light5 = game.Workspace.Streetlights.Light5.LightPart:FindFirstChild("SpotLight")
light6 = game.Workspace.Streetlights.Light6.LightPart:FindFirstChild("SpotLight")
light7 = game.Workspace.Streetlights.Light7.LightPart:FindFirstChild("SpotLight")
light8 = game.Workspace.Streetlights.Light8.LightPart:FindFirstChild("SpotLight")
light9 = game.Workspace.Streetlights.Light9.LightPart:FindFirstChild("SpotLight")
light10 = game.Workspace.Streetlights.Light10.LightPart:FindFirstChild("SpotLight")
light11 = game.Workspace.Streetlights.Light11.LightPart:FindFirstChild("SpotLight")
light12 = game.Workspace.Streetlights.Light12.LightPart:FindFirstChild("SpotLight")
light13 = game.Workspace.Streetlights.Light13.LightPart:FindFirstChild("SpotLight")
light14 = game.Workspace.Streetlights.Light14.LightPart:FindFirstChild("SpotLight")
light15 = game.Workspace.Streetlights.Light15.LightPart:FindFirstChild("SpotLight")
light16 = game.Workspace.Streetlights.Light16.LightPart:FindFirstChild("SpotLight")
light17 = game.Workspace.Streetlights.Light17.LightPart:FindFirstChild("SpotLight")
wall = game.Workspace:FindFirstChild("Grave")
game.Lighting.Changed:connect(function(val)

if game.Lighting.TimeOfDay == "17:00:00" then 
light1.Enabled = true
light2.Enabled = true
light3.Enabled = true
light4.Enabled = true
light5.Enabled = true
light6.Enabled = true
light7.Enabled = true
light8.Enabled = true
light9.Enabled = true
light10.Enabled = true
light11.Enabled = true
light12.Enabled = true
light13.Enabled = true
light14.Enabled = true
light15.Enabled = true
light17.Enabled = true
wall.Transparency = 1
wall.CanCollide = false

elseif game.Lighting.TimeOfDay == "07:00:00" then
light1.Enabled = false
light2.Enabled = false
light3.Enabled = false
light4.Enabled = false
light5.Enabled = false
light6.Enabled = false
light7.Enabled = false
light8.Enabled = false
light9.Enabled = false
light10.Enabled = false
light11.Enabled = false
light12.Enabled = false
light13.Enabled = false
light14.Enabled = false
light15.Enabled = false
light17.Enabled = false
wall.Transparency = 0
wall.CanCollide = true
end
end)

If it works, is there any way to shorten it? If it doesn't work, what's the problem?

2 answers

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

Store all of the lights in a table to make it shorter. To tell the TimeOfDay numerically, use GetMinutesAfterMidnight.

local lights={}
for _,v in pairs(workspace.Streetlights:GetChildren())do
    local l=v:FindFirstChild("LightPart")
    if l then
        lights[#lights+1]=l.SpotLight
    end
end
local wall=workspace.Grave
game.Lighting.Changed:connect(function()
    local minutes=game.Lighting:GetMinutesAfterMidnight()
    if minutes>=1020 or minutes<420 then
        for _,v in pairs(lights)do
            v.Enabled=true
        end
        wall.Transparency=1
        wall.CanCollide=false
    else
        for _,v in pairs(lights)do
            v.Enabled=false
        end
        wall.Transparency=0
        wall.CanCollide=true
    end
end)
Ad
Log in to vote
-1
Answered by
Gxpar 0
9 years ago
light = game.Workspace.Streetlights.Light1.LightPart:FindFirstChild("SpotLight")
wall = game.Workspace:FindFirstChild("Grave")
game.Lighting.Changed:connect(function(val)

if game.Lighting.TimeOfDay == "17:00:00" then

light.Enabled = true

wall.Transparency = 1

wall.CanCollide = false

elseif game.Lighting.TimeOfDay == "07:00:00" then

light.Enabled = false

wall.Transparency = 0

wall.CanCollide = true

end
end)

i havent tested but you can try this.

0
All you did was delete everything. 1waffle1 2908 — 9y

Answer this question