(For information, it intervals in 3 because that’s how much studs apart the lights are)
This is the print of the chir variable, as you can see it only goes for 5 iterations and then restarts, which only lights up 3 lights
Code:
local chir = script.Parent.First.Position.X-3
local sc = false
while wait() do
print(chir)
sc = false
for i,v in pairs(script.Parent:GetChildren()) do
if v~=script then
v.Color = Color3.fromRGB(0,0,0)
v.SurfaceLight.Brightness = 0
end
end
for i,v in pairs(script.Parent:GetChildren()) do
if v~=script then
if v.Position.X==chir then
sc = true
v.Color = Color3.fromRGB(181, 192, 206)
v.SurfaceLight.Brightness = .5
elseif v.Position.X==chir-3 then
sc = true
v.Color = Color3.fromRGB(101, 107, 115)
v.SurfaceLight.Brightness = .25
elseif v.Position.X==chir+3 then
sc = true
v.Color = Color3.fromRGB(101, 107, 115)
v.SurfaceLight.Brightness = .25
end
end
end
if sc==false then
chir = script.Parent.First.Position.X-3
wait(1)
else
chir = chir+3
wait()
end
end
try GetDescendants instead of GetChildren, i’ve had wonky stuff happen with GetChildren in the past, where it outright wouldn’t instance objects correctly, or at all
local chir = script.Parent.First.Position.X-3
local sc = false
while wait() do
print(chir)
sc = false
for i,v in pairs(script.Parent:GetDescendants()) do
if v~=script then
if v:IsA("BasePart") then
v.Color = Color3.fromRGB(0,0,0)
v.SurfaceLight.Brightness = 0
end
end
end
for i,v in pairs(script.Parent:GetDescendants()) do
if v~=script then
if v:IsA("BasePart") then
if v.Position.X==chir then
sc = true
v.Color = Color3.fromRGB(181, 192, 206)
v.SurfaceLight.Brightness = .5
elseif v.Position.X==chir-3 then
sc = true
v.Color = Color3.fromRGB(101, 107, 115)
v.SurfaceLight.Brightness = .25
elseif v.Position.X==chir+3 then
sc = true
v.Color = Color3.fromRGB(101, 107, 115)
v.SurfaceLight.Brightness = .25
end
end
end
end
if sc==false then
chir = script.Parent.First.Position.X-3
wait(1)
else
chir = chir+3
wait()
end
end
Yes, but 3 is being added to chir every iteration of the loop, and chir only resets back to its initial value after there is no part with an X that’s equal to chir or 3 less or more than chir
I feel like the best thing you should do is loop through every part in the folder and not get a certain position. You can number these parts from 1 to the max number and use your iteration value as the identifier
With your method, it gets really confusing especially when dealing with specific positions
Hell naw, I won’t number my parts, it’s going to take eternity. Besides, it’s not robust either, if I want to create a copy of this, I’ll have to position them all one by one, or just create new ones and renumber them.