Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to check if one of two values have not yet been enabled after 230 secs or before?

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.

4 comments

0

I'm sorry, what is the problem?

0

Oh wait

0

Maybe try making a wait() and after the wait make an if statement that checks if the zombies and boss are dead..?

0

@ZIRFAL3 Ill make a wait in a seperate script

1 answer

✓ Accepted answer

The logic flow you need is this:

  1. Connect to all the events you want to listen to. Be sure to either only connect once or else disconnect from them when you no longer need them. Whenever any of them fire, do whatever you would like to do in response, but also make sure you've recorded in a variable that one of these events has taken place. Make sure this prevents the other event handlers from doing anything, if appropriate.
  2. Wait for 230 seconds.
  3. If no event handlers have been run, then run the default behaviour (whatever you want to have happen after 230 seconds if no event has fired)
-- 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

2 comments

0

Wow. Thanks a lot

0

Wow. Thanks a lot. I was just going to use spawn() and coroutines but this works! Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.