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

How can I make it so when a there is only one player alive the loop breaks?

Asked by 5 years ago
Edited 5 years ago
01while true do
02 
03 
04game.Workspace.BackGroundMusic:Play()
05local text = game.ReplicatedStorage.TextValue
06local plrsleft = #game.Players:GetChildren()
07local pL = game.Players
08 
09        while true do
10        local plrsleft = #game.Players:GetChildren()
11        print("Not enough players...")
12        text.Value = "Not enough players..."
13        wait(1)
14        if plrsleft >= 1 then
15        wait(1)
View all 69 lines...
0
I really wish people would preview their post before posting. ScuffedAI 435 — 5y
0
me too TheRealPotatoChips 793 — 5y
0
Please use the little blue button on the top to format your code. It's really hard to read and thus makes it hard for us to help you. Sensei_Developer 298 — 5y
0
oh Hederlunden 19 — 5y
View all comments (4 more)
0
I fixed it now... Sorry about that... Hederlunden 19 — 5y
0
you could've edited your post rather than creating a new answer. Mayk728 855 — 5y
0
didn't know you could do that... Hederlunden 19 — 5y
0
Ok, now I have changed the whole thing... Please help me... Hederlunden 19 — 5y

1 answer

Log in to vote
0
Answered by
Mayk728 855 Moderation Voter
5 years ago
Edited 5 years ago

you can't have two while loops running simultaneously. one loop should be enough to do the job.

EDIT: fixed player checking

001local text = game:GetService('ReplicatedStorage'):WaitForChild('TextValue')
002local Players = game:GetService('Players')
003local PlayersLeft
004 
005local IsPlayingFolder = Instance.new('Folder')
006IsPlayingFolder.Parent = game:GetService('ServerStorage')
007 
008function DoubleCheck()
009    local pl = #Players:GetChildren()
010    if pl <= 1 then
011        return true
012    else
013        return false
014    end
015end
View all 100 lines...
0
Thank you so much! Btw, do you know a way I can print the name of the player who won? Hederlunden 19 — 5y
0
when the round starts, you'd have to create a value for each player showing that they're in the game. once they're eliminated, remove the value. eventually, if only one person has a value, they're the winner. Mayk728 855 — 5y
0
Hmm... I'm kinda new to scripting so can you show an example of that? Hederlunden 19 — 5y
0
i've edited the script. if it works, please upvote. i spent 40 min on this lol. Mayk728 855 — 5y
View all comments (13 more)
0
21:11:24.988 - ServerScriptService.Test:51: attempt to index nil with 'Character' Hederlunden 19 — 5y
0
:/ I'm sorry... Hederlunden 19 — 5y
0
that's my bad! i just did another edit, go ahead and try again. :) Mayk728 855 — 5y
0
everything was going great but... this is probably the last bug... 21:32:35.281 - ServerScriptService.Test:90: attempt to concatenate nil with string Hederlunden 19 — 5y
0
made an edit to line 90, try again o.O and i apologize for the errors, i can't test this script each time so things are bound to happen. Mayk728 855 — 5y
0
ServerScriptService.Test:90: attempt to concatenate boolean with string im sorry Hederlunden 19 — 5y
0
LOL my bad, i should be sorry here. made another adjustment to line 90. if there's still an error, you can add me on Roblox and i can continue further testing with you. Mayk728 855 — 5y
1
do you know why it never gets to print("four?") return end print("four?") --moving on? end end Hederlunden 19 — 5y
0
not sure what that's supposed to mean? Mayk728 855 — 5y
1
its in the end of the script but I added a print("four") to see how long the script would go. But it never got to that and after a player wins, I want to repeat it (i will add more later)) Hederlunden 19 — 5y
0
it's because at line 96, i added "return" which restarts the while loop. you can remove it and it should print what you wanted after. Mayk728 855 — 5y
1
Dude.. Thank you so much for all of this! If I could upvote I would but I don't have enough reputation. :(. But I will definetly remember this and upvote when I can! Hederlunden 19 — 5y
0
np!! :D Mayk728 855 — 5y
Ad

Answer this question