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

local function Start ()

    script.Parent.Text = 30

    for i=1, 30 do

        wait(1)

        script.Parent.Text = script.Parent.Text - 1

    end

    Workspace.Events.Restart:FireAllClients()

end)

Workspace.Events.Start.OnServerEvent:Connect(Start)

--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.

local function Start ()

    local players = workspace.NumberOfPlayers.Value -- lets imagine this int value have the          
        amount of players currently in the game

    local currently = instance.new("intvalue", workspace)
    currently.Name = currently
    currently.Value = NumberOfPlayers.Value -- sets the number players who is playing

    script.Parent.Text = 30

    for i=1, 30 do

        wait(1)

        script.Parent.Text = script.Parent.Text - 1

        if currently == 1 then break -- im not used to "break" so if anything is wrong pls tell

    end

    Workspace.Events.Restart:FireAllClients()

end)

Workspace.Events.Start.OnServerEvent:Connect(Start)

--if you see misspelled things please forget it, i'm not in studio

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:

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

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