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

Issues with checking the number of players ingame?

So I'm quite new to scripting so I'm not sure if you can use .NumPlayers to check the value of how many people are ingame. I need it so that it checks if there are more than 2 players ingame then if there is it will continue, any help will be much appreciated. Thanks.

local Hint = Instance.new("Hint", game.Workspace)

if game.Players.NumPlayers >=2 then
	for Time = 15,1, -1 do
		wait(1)
		Hint.Text = Time
	end
end

3 comments

0

What's the problem?

0

Any errors?

0

No errors, I'm just confused on how to check the number of players.

1 answer

✓ Accepted answer

You are using the right method, NumPlayers. Even when you are new to scripting your code is actually okay! The problem is that you're trying to check if there are less than or equal to 2 players. So you need to have less than 3 to activate the script. game:GetService("Players").NumPlayers <= 2 bad, 2 <= game:GetService("Players").NumPlayers good.

--How I would write this script
local playersneeded = 2 --How many players needed.

if playersneeded <= game:GetService("Players").NumPlayers then
	local hint = Instance.new("Hint", workspace)
	for Time = 15,1,-1 do
		wait(1)
		hint.Text = Time
	end
end

Hope it helps!

1 comment

0

Thank you.

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