So, I've been working on a vehicle's emergency lighting for the last few days and it works well in an empty game, but in live use it tends to get quite slow in the emergency lights. The coding essentially involves going light by light and telling it to be on or off. Is there a more efficient way to do this?
lightbar.part1.Enabled = true lightbar.part2.Enabled = false
multiply that by about 20 for every single section of the pattern (tends to have 5-6 different sections)
If you don't really understand what I mean, I am trying to make a emergency lightbar with realistic emergency patterns... look up emergency lighting patterns
For example, here is how it is in the live server: https://gyazo.com/74045ad0678d5293d5be7a0d1b7f044f
And this is what it should look like: https://gyazo.com/74045ad0678d5293d5be7a0d1b7f044f
function turnLightOff(IDs, a, original) for k,v in pairs(a) do for l,x in pairs(IDs) do if v.Name == x then v.Lighto.Enabled = true else v.Lighto.Enabled = false end end end end turnLightOff({"B2","R1","R3","B13","B15","R12","R14"}, MainVeh:GetChildren()) wait(10) turnLightOff({"B1","B3","R2","B12","B14","R13","R15"}, MainVeh:GetChildren())
Is this what you wanted?
function turnLightOff(IDs, a, original) for k,v in pairs(a) do for l,x in pairs(IDs) do if v.Name == original..x do v.Enabled = true else v.Enabled = false end end end end --[[ FUNCTION ARGUMENTS: [Table] IDs = The part numbers you want to be turned off. [Table] p = The table the parts are in. [String] original = The original name of the part without the ID in it. --]] --EXAMPLE: --lets say workspace has 10 lights in it. All named: "Part1", "Part2", "Part3" etc. turnLightOff({5,6}, game.Workspace:GetChildren(), "Part") --run this --All of the light in workspace have turned off except for "Part5" and "Part6", those two are still on.
In your case:
function turnLightOff(IDs, a, original) for k,v in pairs(a) do for l,x in pairs(IDs) do ifif v.Name == original..x then v.Lighto.Enabled = true else v.Lighto.Enabled = false end end end end turnLightOff({"2","13","15"}, MainVeh:GetChildren(),"B") turnLightOff({"1","3","14"}, MainVeh:GetChildren(),"R") wait(10) turnLightOff({"1","3","12","14"}, MainVeh:GetChildren(),"B") turnLightOff({"2","13","15"}, MainVeh:GetChildren(),"R")