Please help me this is actually frying my brain and I cant stand it Ok so, I have a boss fight thing that you have to try and kill "zombies" and the boss before an invisible timer runs out (nobody sees the timer), Im using bindable events and BoolValues to help do this.
--just pretend it will always be infection wait(10) while true do math.random(1,3) if math.random(1,3) == 1 then game.ServerScriptService.eventos.LAVA_AH.Disabled = false print("lava") wait(66) game.ServerScriptService.eventos.LAVA_AH.Disabled = true print("lava over") script.Disabled = true elseif math.random(1,3) == 2 then game.ServerScriptService.eventos.NUKE_AH.Disabled = false print("nuke") wait(131) game.ServerScriptService.eventos.NUKE_AH.Disabled = true print("nuke OVER") script.Disabled = true elseif math.random(1,3) == 3 then game.ServerScriptService.eventos.INFECTION_AH.Disabled = false wait(230) game.ReplicatedStorage.WHENAVALISTRUE.Event:Connect(function(winorlose) --bindableEvent if winorlose == "loss" then end end) end end
the script that is firing the event:
game.ReplicatedStorage.booleans.bacLose.Changed:Connect(function() if game.ReplicatedStorage.booleans.bacLose.Value == true then game.ReplicatedStorage.WHENAVALISTRUE:Fire("loss") --WHENAVALISTRUE is the BindableEvent end --ill add other win Ifs later but this is just for now end)
I havent even tested it out yet because I cant
Summary: If one of these two values have not yet been enabled even after 230 seconds have passed remove everything.
The logic flow you need is this:
-- Example using arbitrary events for demonstration local win = Instance.new("BindableEvent") local loss = Instance.new("BindableEvent") local function play() local victory, defeat local winCon = win.Event:Connect(function() victory = true print("Victory!") end) local lossCon = loss.Event:Connect(function() defeat = true print("Defeat!") end) wait() -- short game :) if not victory and not defeat then print("Timed out.") end winCon:Disconnect() lossCon:Disconnect() end for num = 1, 3 do print("Round", num) task.spawn(play) -- Think of this as the same as "play()" except that it happens on a new thread, so we don't wait for it to finish when it waits. -- local num = math.random(1, 3) -- Tip: always save this to a variable first or else you'll get a different number each time you call it. I've got this disabled (and am using the for loop) so you can see all 3 outcomes quickly. if num == 1 then win:Fire() elseif num == 2 then loss:Fire() end wait(0.2) end