Still have questions? Join our Discord server and get real time help.
Log in to vote

Check for a certain amount of players in-game?

Asked by 7 months ago

(This is a Local Script) Hello, I was wondering If there was a way to check if there is a certain amount of players in game? I'm trying to do this because I want to make a Murder-Mystery game and wait until there's at least 2 players for the round to start. I tried this code:

local getplayers = game:GetService("Players")
local player = game.Players.LocalPlayer
if getplayers >= 2 then
    player.PlayerGui:WaitForChild("ScreenGui").Frame.Visible = true

But it didn't work. Any help?

1 answer

Log in to vote
Answered by 7 months ago

The problem here is that you are comparing a table of players to a number. Using the # identifier allows you to get the amount of items in a table.

if #game.Players:GetPlayers() >= 2 then
    -- stuff

Hope this helped, and make sure to accept my answer if it did.


Answer this question