Alright so I have a script here with two functions that will be called randomly but only if there is not an ongoing “event”/function running. 90% off the script works. It picks a random event once and then no more even when the “event” is done running
Script:
local myFunctions = {}
local dummyTable = {}
local EventBoard = workspace.EventBoard
local FiveNineFour = EventBoard.FiveNineFour
local EventLight = workspace.LightFolder.Pin
local OldLightVal = Color3.fromRGB(213, 115, 61)
local ProximityPrompt = workspace.Station1.StationPart.ProximityPrompt
local OngoingEvent = false
local StatusText = EventBoard.StatusText.SurfaceGui.Frame.TextBox.Text
myFunctions.Event1 = function()
OngoingEvent = true
FiveNineFour.Status.Color = Color3.new(1, 0, 0)
EventLight.Color = Color3.new(1, 0, 0)
ProximityPrompt.Enabled = true
StatusText = "One or several stations are experiencing outages"
end
--Waiting for event to stop
ProximityPrompt.TriggerEnded:Connect(function()
FiveNineFour.Status.Color = Color3.new(0, 1, 0)
EventLight.Color = OldLightVal
ProximityPrompt.Enabled = false
OngoingEvent = false
end)
myFunctions.Event2 = function()
print("Just using this for debugging")
end
for index, func in pairs(myFunctions) do -- loops through the functions table
table.insert(dummyTable, index) -- adds the index to the dummy table
-- the index would be something like:
-- myFunctions.no = function() | "no" would be the index
end
local function EventPick()
while ProximityPrompt.Enabled == false do
wait(5)
myFunctions[dummyTable[math.random(1, #dummyTable)]]()
end
end
EventPick()