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

How to trigger a function if the player count is too low?

Asked by 4 years ago
Edited 4 years ago

It was underlined in red when I wrote this:

1if Players == <5 then
2    print ("not enough players!")
3end

the '<' symbol is underlined in red? how do I fix this?

2 answers

Log in to vote
0
Answered by 4 years ago

Code

Essentially you want to run an if statement checking if the player count is lower than 5. You can do this by checking every time a player joins.

01local val = 5 -- player limit
02 
03function check()
04    if #game.Players:GetChildren() < val then -- # is essentially converting a value in to number.
05        return true
06    else
07        return false
08    end
09end
10 
11game.Players.PlayerAdded:Connect(function()
12    local val1 = check() -- getting returned value
13    if val1 == true then -- if there are less than 5 players
14        -- execute function
15        print("Less than 5 players are in")
16    else
17        print("More than 5 players are in!")
18    end
19end)
Ad
Log in to vote
0
Answered by 4 years ago

Yay, it's solved. Here's the solution. I made a value in the 'Players' tab, it adds 1 whenever 1 player joins.

1local Players = game.Players
2local PlayerNumber = game.Players.PlayerNumber
3Players.PlayerAdded:Connect(function()
4    PlayerNumber.Value = PlayerNumber.Value + 1
5end)

This one is the if and then statement, I tried it without the '==' this time.

01local map1 = game.workspace.Map1
02local map2 = game.workspace.Map2
03local map3 = game.workspace.Map3
04local Players = game.Players
05local PlayerNumber = game.Players.PlayerNumber
06local playercountdeny = 'not enough players'
07if PlayerNumber.Value < 8 then
08    print (playercountdeny)
09 
10end
0
This will glitch. Did you add a minus 1 function for a person leaving the game? Xapelize 2658 — 4y

Answer this question