I want to make my lights/indicators light up randomly. So far this is my script:
local items = script.Parent.Folder:GetChildren()
local randomItem = items[math.random(1,#items)]
while true do
for _,v in pairs (randomItem:GetChildren()) do
if v:IsA("Model") and v.Name == "Indicator" then
v.Ind.Material = Enum.Material.Neon
task.wait(.5)
v.Ind.Material = Enum.Material.SmoothPlastic
end
end
task.wait()
end
I’ve tried countless methods but to no avail. Can somebody tell me why it doesn’t work?
Currently you pick a random item once, then when the loop runs this random item never changes.
You need to place the random item declaration line inside the loop.
(I’m assuming the paths are correct for the parts)
local items = script.Parent:GetChildren()
while true do
local randomItem = items[math.random(1,#items)]
for _,v in pairs (randomItem:GetChildren()) do
if v:IsA("Model") and v.Name == "Indicator" then
v.Ind.Material = Enum.Material.Neon
task.wait(.5)
v.Ind.Material = Enum.Material.SmoothPlastic
end
end
task.wait()
end
local items = workspace.RandomIndicators.Folder:GetChildren()
while task.wait(2) do
local randomItem = items[math.random(1,#items)]
print(randomItem)
for _,v in pairs(randomItem:GetChildren()) do
print("loop")
v.Ind.Material = Enum.Material.Neon
task.wait(0.5) -- Changed from task.wait() to wait()
v.Ind.Material = Enum.Material.SmoothPlastic
end
end