I want to wait for when a tween finishes, but if another tween starts, it will cancel the first one and wait for the new one to finish
But, when the second tween starts, the first tween gets canceled and it stops waiting, causing an unwanted firing of my remote event.
–Serverside
local function WinDecider(Winner)
if Winner == "Attackers" then
WinBar:FireAllClients("Attackers")
AttackerWin=true
elseif Winner == "Defenders" then
WinBar:FireAllClients("Defenders")
DefenderWin=true
end
if AttackerWin and DefenderWin then
Draw=true
WinBar:FireAllClients("Draw")
end
end
–Clientside
WinBar.OnClientEvent:Connect(function(Winner)
if Winner=="Attackers" then
AttackerWin:Play()
AttackerWin.Completed:Wait()
elseif Winner=="Defenders" then
DefenderWin:Play()
DefenderWin.Completed:Wait()
elseif Winner=="Draw" then
AttackerWin:Pause()
DefenderWin:Pause()
Draw:Play()
Draw.Completed:Wait()
end
print("a")
WinBar:FireServer()
end)
A breakdown of how it should work goes: The winDecider runs if the timer runs out or the health reaches 0, firing the remote events with their respective keywords. Then it will play the respective tween and wait for the tween to finish before letting the serverside script continue.
If both the timer and the health reach 0 before the tween finishes, then first, the other win condition fires and starts waiting. And then Draw fires. Draw, then pauses the other two and waits for its own.
Here is where the problem lies. The pausing merely makes the other waits finish instantly and then fires the server. I see this as it prints “a” three times instead of once.
I need to find a way to stop the first 2 tweens from firing once draw starts.
I have tried a combined repeat wait() until (all 3 of the tweens.PlaybackState ~= Playing), But I could not get that to work for some reason.