Trouble checking if there are more than 2 players in a place

So today my problem is this:
I made a script whose function is to check if there are more than 2 players in place and then a BoolValue will be active, only I don’t understand what I did wrong in the script:

local Players = game:GetService(“Players”)

local PlayerModels = Players:GetChildren()

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

local BoolsFolder = ReplicatedStorage.Bools

while BoolsFolder.twoormore.Value == false do

if #PlayerModels >= 2 then

print(“more 2 players in place”)

BoolsFolder.twoormore.Value = true

end

wait()

end

Any way to get this to work?

1 Like

as well? what do you mean by that?

local Players = game:GetService(“Players”)

local PlayerModels = Players:GetChildren()

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

local BoolsFolder = ReplicatedStorage.Bools
while BoolsFolder.twoormore.Value == false do

    if #PlayerModels >= 2 then

	     print(“more 2 players in place”)

	     BoolsFolder.twoormore.Value = true

    end

	wait()
end

this is the right format

I tested it on a server and it doesn’t work, I did it on serverscriptservice in a script.

It’s the same code. But yours wasn’t in the right format you should write your codes using preformatted text.

1 Like

in my script it’s pre-formatted but here I don’t know why whenever I copy a script here it looks like this

PlayerModels is initially defined, you should define it inside the loop or just directly embed it in the statement.

1 Like

If your using a Server Script, you should put your Values in ServerStorage rather than ReplicatedStorage

1 Like

The script still doesn’t work, but it was good to realize what you mentioned about serverstorage

local Players = game:GetService("Players")

local Bool = ... -- Location of your bool value

function Update()
  Bool.Value = #Players:GetPlayers()>=2
end

Players.PlayerAdded:Connect(Update)
Players.PlayerRemoving:Connect(Update)
1 Like
local Players = game:GetService(“Players”)

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

local BoolsFolder = ReplicatedStorage.Bools
while BoolsFolder.twoormore.Value == false do

    if #Players:GetChildren() >= 2 then

	     print(“more 2 players in place”)

	     BoolsFolder.twoormore.Value = true

    end

	wait()
end
1 Like

I’ve seen the problem, you were right after all

1 Like