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

Does anyone know how i'd change this to effect all children within a folder?

Asked by
RLX_Dev -5
2 years ago
b = script.Parent

local oh,om = 6,30  -- Daytime
local ch,cm = 17,30 -- Nighttime

local l = game:service("Lighting")
if (om == nil) then om = 0 end
if (cm == nil) then cm = 0 end


function TimeChanged()
    local ot = (oh + (om/60)) * 60
    local ct = (ch + (cm/60)) * 60
    if (ot < ct) then
        if (l:GetMinutesAfterMidnight() >= ot) and (l:GetMinutesAfterMidnight() <= ct) then
            b.Material = "SmoothPlastic"
            b.Reflectance = "0.45"
            b.Color = Color3.new(0.47451, 0.482353, 0.513725)
            b.PointLight.Enabled = false
        else
            b.Material = "Neon"
            b.Reflectance = "0"
            b.Color = Color3.new(0.639216, 0.576471, 0.454902)
            b.PointLight.Enabled = true
        end
    elseif (ot > ct) then
        if (l:GetMinutesAfterMidnight() >= ot) or (l:GetMinutesAfterMidnight() <= ct) then
b.Transparency = 0
        else
b.Transparency = 0
        end
    end
end

TimeChanged()
game.Lighting.Changed:connect(function(property)
            if (property == "TimeOfDay") then
                TimeChanged()
            end
        end)

The current version above fully works but for it to work the script itself has to be inside each individual part/union.

I want to try make it so a single script changes multiple parts/lights so lag ins't too bad.

I know it has something to do with :GetChildren but i'm unsure of how to set this up and have tried multiple times by reading through the devforum as well as youtube.

Appreciate the help!

0
if you don't want to loop through every part every time the time changes then you can try something like this, i didnt know what the ot ct abcd things meant so you would have to modify https://pastebin.com/KT26zzuP enzotinman1 23 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

try changing it to this

local oh,om = 6,30  -- Daytime
local ch,cm = 17,30 -- Nighttime

local l = game:service("Lighting")
if (om == nil) then om = 0 end
if (cm == nil) then cm = 0 end


function TimeChanged(b)
    local ot = (oh + (om/60)) * 60
    local ct = (ch + (cm/60)) * 60
    if (ot < ct) then
        if (l:GetMinutesAfterMidnight() >= ot) and (l:GetMinutesAfterMidnight() <= ct) then
            b.Material = "SmoothPlastic"
            b.Reflectance = "0.45"
            b.Color = Color3.new(0.47451, 0.482353, 0.513725)
            b.PointLight.Enabled = false
        else
            b.Material = "Neon"
            b.Reflectance = "0"
            b.Color = Color3.new(0.639216, 0.576471, 0.454902)
            b.PointLight.Enabled = true
        end
    elseif (ot > ct) then
        if (l:GetMinutesAfterMidnight() >= ot) or (l:GetMinutesAfterMidnight() <= ct) then
b.Transparency = 0
        else
b.Transparency = 0
        end
    end
end

TimeChanged()
game.Lighting.Changed:connect(function(property)
            if (property == "TimeOfDay") then
                for i,b in pairs(script.Parent:GetChildren()) do
            TimeChanged(b)
        end
            end
        end)

if it doesn't work then maybe try changing

for i,b in pairs(script.Parent:GetChildren()) do
    TimeChanged(b)
end

to

for i,b in next, script.Parent:GetChildren() do
    TimeChanged(b)
end
Ad

Answer this question