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

How do i get check if only one "playing" player is left?

Asked by
CjayPlyz 643 Moderation Voter
6 years ago
Edited 6 years ago

Here a script

01local function Start ()
02 
03    script.Parent.Text = 30
04 
05    for i=1, 30 do
06 
07        wait(1)
08 
09        script.Parent.Text = script.Parent.Text - 1
10 
11    end
12 
13    Workspace.Events.Restart:FireAllClients()
14 
15end)
16 
17Workspace.Events.Start.OnServerEvent:Connect(Start)
18 
19--if you see misspelled things please forget it, i'm not in studio

Now, what if i want to make the loop to stop if a there are only _ "playing" player is left.

01local function Start ()
02 
03    local players = workspace.NumberOfPlayers.Value -- lets imagine this int value have the         
04        amount of players currently in the game
05 
06    local currently = instance.new("intvalue", workspace)
07    currently.Name = currently
08    currently.Value = NumberOfPlayers.Value -- sets the number players who is playing
09 
10    script.Parent.Text = 30
11 
12    for i=1, 30 do
13 
14        wait(1)
15 
View all 28 lines...

Now how do i make "currently" negate if a player died?

2 answers

Log in to vote
1
Answered by 6 years ago

You could use tables.

Here is how you could use them:

On the start of game add all players to the table Detect if a player has died then remove them from table Once there is one person left then end game and reward the player

0
thanks CjayPlyz 643 — 6y
0
No problem :) NoirPhoenix 148 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

You could make a BoolValue with the name "InGame" then if theyre ingame make it check "True" and if they die.. make it so it goe's to false.. Then do for example:

1for i,v in pairs(game.Players:GetChildren()) do
2    if v.InGame.Value == true then
3        print(v.Name)
4    end
5end

This would be much easier then the method with tables above this (In my opinion)

0
and then make it if theres only 1 player left.. with if v > 1 then i guess CrazyScript3r 67 — 6y

Answer this question