I’m having small problem with my game. I’m trying to make it so that a function will be looping until a BindableEvent is called.
Here is an example:
while true do
gameFunction() -- I want this to keep looping until the event is called
local winnerFound = roundEnd.Event:Wait(1)
if winnerFound == true then
However it appears that it just keeps waiting indefinitely… is there a better way to do this? roundEvent is waiting until there is one player left to be called. I thought about using :Connect, but I’m not entirely sure how to implement that in a loop.
Event:Wait() just waits until its fired again, so you just need to fire that event from the script when you want to continue.
you can do something like this:
local winnerEvent = game:GetService("ReplicatedStorage").Event
eventConn = winnerEvent.Event:Connect(function(winnerPlr)
eventWinner = winnerPlr
while not eventWinner do
print("do game function here")
print("the winner is:", eventWinner)
while true do
Any wait will yield the thread, making it so you don’t need an if statement, it just will run when the wait’s time has elapsed!
Also, passing a number in
roundEnd.Event:Wait() does virtually nothing, it’s not normal wait. It will wait until the event is fired, then continue the thread.
Sorry, for the late reply. I found that Brain’s solution best fit my situation, and after a few modifications I was able to make it work. Thank you guys for replying!
Unfortunately, this does the same thing as my original script did