As large as this adjusted script for slightly better customizability and reducing the use of multiple loops for a single model and providing customizability.
This would allow you to make multiple parts with different names and have a different strobe effect.
local Rand = Random.new()
function setVisibility(v,name,transparency)
for i,v in next,v:GetChildren() do
if v.Name==name and v:IsA("BasePart") then
v.Transparency=transparency
end
end
end
local modules={};
-- modules['part name to visualize']
-- if a model with 'on' and the part name in [ -- ] exists,
modules['FlashingLight']=function(v)
while v.Parent~=nil do
wait(Rand:NextNumber(0.01, 0.1))
if v.on.Value == true then
setVisibility(v,"FlashingLight",0)
--This function will set all items in the model with the name of 'FlashingLight' to the next number.
wait(0.03)
setVisibility(v,"FlashingLight",1)
wait(0.03)
setVisibility(v,"FlashingLight",0)
wait(0.03)
setVisibility(v,"FlashingLight",1)
wait(0.03)
setVisibility(v,"FlashingLight",0)
wait(0.3)
setVisibility(v,"FlashingLight",1)
wait(0.3)
else
setVisibility(v,"FlashingLight",1)
wait(.5) -- better to wait a bit more if it's off.
end
end
end
modules['FlashingLight2']=function(v)
while v.Parent~=nil do
wait(Rand:NextNumber(0.01, 0.1))
if v.on.Value == true then
setVisibility(v,"FlashingLight2",0)
wait(0.3)
setVisibility(v,"FlashingLight2",1)
wait(0.3)
else
setVisibility(v,"FlashingLight2",1)
wait(.5) -- better to wait a bit more if it's off.
end
end
end
local modulesExisting={}
for i,v in next,modules do
modulesExisting[i]=true
-- Helps convert modules into a true/false quick check.
end
function HookLightGroup(model)
local foundModules={}
local foundModNum=0;
for i,item in next,model:GetChildren() do
if modulesExisting[item.Name] then
print("Module for ",item.Name)
foundModules[item.Name]=true;
foundModNum+=1;
end
end
if foundModNum>0 then
for modulename,v in next,foundModules do
print("Running ",modulename)
task.spawn(function()
modules[modulename](model)
end)
end
else
print("No modules found for ",model)
end
end
--Handling of grabbing any folder/model with 'on' boolvalue inside.
for i,v in next,workspace:GetDescendants() do
local x,y=pcall(function()
if v.Name=="on" and v.ClassName=="BoolValue" then
HookLightGroup(v.Parent)
end
end)
if not x then
warn("LocalLight Issue possible, ",y)
end
end
workspace.DescendantAdded:Connect(function(v)
local x,y=pcall(function()
if v.Name=="on" and v.ClassName=="BoolValue" then
HookLightGroup(v.Parent)
end
end)
if not x then
warn("LocalLight Issue possible, ",y)
end
end)
You are free to remove the prints if necessary. They’re simply debugging.