Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to end round when there is one player left?

Asked by
Dekishi 12
4 years ago

I have a round based system for a fighting game I am working on, but I am wondering how to end the round when there is one player left. I have a folder in the workspace called Ingame where players are stored while in the round. i also have a string value in Replicated Storage called Winner. which will store the name of the last player. How do I change the value of the string once there is one player left? Thanks.

0
Use the PlayerRemoving Event. game.Players.PlayerRemoving:Connect(function) Spjureeedd 385 — 4y

1 answer

Log in to vote
1
Answered by
crywink 419 Moderation Voter
4 years ago
Edited 4 years ago

Hey!

If you're storing them all in a folder, you can use the ChildRemoved event on the folder to see when a player has left/been disqualified. After that, you can check how many instances are in the respective folder to see how many are left! An example of how this can be used is shown below...

folder.ChildRemoved:Connect (function()
    if #folder:GetChildren() <= 1 then
        print("1 or less players remaining!")
    end
end)

If you didn't know already, folder:GetChildren() gathers a table with all of the instances in that folder and the # operator tells us how many indices are in that table. Using them together, we can determine how many instances are in the folder.

Hope this helped! If it did, please remember to mark as answered and upvote.

1
Thanks man, saved my game. Dekishi 12 — 4y
Ad

Answer this question