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

Issues with checking the number of players ingame?

Asked by
DevWork 80
9 years ago

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
0
What's the problem? Relatch 550 — 9y
0
Any errors? Relatch 550 — 9y
0
No errors, I'm just confused on how to check the number of players. DevWork 80 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

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!

0
Thank you. DevWork 80 — 9y
Ad

Answer this question