So basically, my little cousin is super into Fire Alarms, and I thought I would script a Fire Alarm set for him so he can use it in his games. I'm having trouble with an in pairs loop and getting it to find all parts in a model named "Strobe", and making them do as expected, strobe (Namely changing the material to neon and making a point light brighter then reversing the changes to make a bright flashing light).
Anyways, here is the code. Ignore the giant clunky loop, I'm too lazy to make it more efficient (even though that may be part of the problem):
-- {{ Setting Variables }} --
local h = script.Parent.Parent
local c = script.Parent
local f = workspace.AlarmSet.Strobe
local a = workspace.AlarmSet
local s = workspace.AlarmSound
local p = f.PointLight
-- {{ Main Strobe Function }} --
c.MouseClick:Connect(function() --Linking a function to the click of the handle
s:Play()
local parts = a:GetChildren()
for i,v in pairs(parts) do
if v.name == "Strobe" then
while true do --Setting up a giant loop to cycle through
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.8)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.8)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(0.05)
v.Material = "Neon"
v.PointLight.Brightness = 5
wait(1.6)
end
end
end
end)
Also the comments are to help him with coding in the future, let me know if they are stupid lol

3 comments
holy crap that indentation is bad. why do people still turn tabs into spaces? maaaan..
LMAO that intro got me I'll let you know if it works
Awesome! It works great. Thanks for the help, I'll be sure to look into spawn and coroutines in the future (although they seem to be a bit advanced for me).