Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

2 comments

0

thanks

0

No problem :)

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)

1 comment

0

and then make it if theres only 1 player left.. with if v > 1 then i guess

This discussion is preserved as it was. New answers, comments, and votes are closed.