Greetings, Roblox Forum. This is my first post; I’m excited to ask questions and learn more on the platform!
Now, my issue:
For quite some time I’ve been looking to accomplish making an alarm system that utilizes multiple systems to let you know that… there is an alarm for something happening. The first rendition of this, thanks to a scripting friend long ago, was to have a script in every single instance to accomplish this, and for a long while it worked at the great expense of lag and slowdown of the game.
In the past couple years I have taken to learning coding myself, and I’ve recently discovered the value of the CollectionService and tagging to which I’ve used elaborately for individual items activated by players via prompt.
Utilizing this, I dared to condense the entire system into a single script, and it actually works!- With a catch, however; one that I can’t seem to find a way around no matter how hard I try.
To run it down, there is a console with 4 buttons for 4 values: 0 is disabled, 1-3 is raising levels of alarm. I was able to successfully make all the components align with this, however, with how I have been traditionally scripting, (instances working independently) it worked more like a row of dominos… (So if there was a row of lightbulbs they would turn on one by one)
To just grasp how to rewrite all of this (after many hours of fruitlessly failing at comprehending coroutines and considering I may be approaching this wrong), I want to share how it’s scripted so far, and get help figuring out where I’m going wrong. (Sorry if this is such a huge blurb, first time lol) I think I can figure out improving it if I just get a point in the right direction.
Here’s my coding!
local CollectionService = game:GetService("CollectionService") --roblox stuff
local ProximityPromptService = game:GetService("ProximityPromptService")
local button = workspace.AMBRESEVSystem.Console.BRESEVButton --the console
local bresev = script.AlarmValues.BRESEV --"alarm" values 0-3
local breach = script.AlarmValues.Breach --true/false value
local debounce = script.AlarmValues.Debounce --debounce
ProximityPromptService.PromptTriggered:Connect(function(Prompt,Player) --the player interacts with the console
if (CollectionService:HasTag(Prompt.Parent,"BRESEV")) then --the console has a special tag "BRESEV"
--Console
if debounce.Value == false then --checksum to not allow spam
debounce.Value = true
if Prompt.KeyboardKeyCode == Enum.KeyCode.H then --BRESEV 0
bresev.Value = 0
breach.Value = false
elseif Prompt.KeyboardKeyCode == Enum.KeyCode.J then --BRESEV 1
bresev.Value = 1
breach.Value = true
elseif Prompt.KeyboardKeyCode == Enum.KeyCode.K then --BRESEV 2
bresev.Value = 2
breach.Value = true
elseif Prompt.KeyboardKeyCode == Enum.KeyCode.L then --BRESEV 3
bresev.Value = 3
breach.Value = true
end --the system enters a different value based on what the player selects
--Alarm Lights
for _, part in pairs(CollectionService:GetTagged("BSAL")) do --each light instance is tagged with this
local part = part --the tagged brick
local LT = part:FindFirstChild('LightType') --a variable to check for the light; there are 3 types
local function flash()
while breach.Value == true do
wait(0.775)
part.Light.Enabled = false
part.Parent.Alarm.Material = Enum.Material.SmoothPlastic
wait(0.934)
part.Light.Enabled = true
part.Parent.Alarm.Material = Enum.Material.Neon
end
end
local function spin()
while breach.Value == true do
part.CFrame = part.CFrame * CFrame.fromEulerAnglesXYZ(0.15, 0, 0)
wait(0.05)
end
end
local function lightsoff()
if LT.Value == 1 then --a light that just turns on
wait(1.5)
part.effectsAtt.Light.Enabled = false
part.Material = Enum.Material.Ice
elseif LT.Value == 2 then --a light that flashes on and off
wait(1.5)
part.Light.Enabled = false
part.Parent.Alarm.Material = Enum.Material.SmoothPlastic
elseif LT.Value == 3 then --a light that spins
wait(1.5)
part.Parent.Case.BrickColor = BrickColor.New("Dusty Rose")
part.LightF.Enabled = false
part.LightB.Enabled = false
end
end
if breach.Value == true then
if LT.Value == 1 then --red
part.effectsAtt.Light.Enabled = true
part.Material = Enum.Material.Neon
elseif LT.Value == 2 then --flash
spawn(flash)
elseif LT.Value == 3 then --spin
part.LightF.Enabled = true
part.LightB.Enabled = true
part.Parent.Case.BrickColor = BrickColor.New("Really Red")
spawn(spin)
end
elseif breach.Value == false then
spawn(lightsoff)
end
end
end
wait(5)
debounce.Value = false
end
end)
So this coding does work as I mentioned, but again, acts like a row of dominos where it has to go through each at a time (let’s say for example there are 50 lights). What are some tips on reformatting this? Thanks in advance!!