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 3 years ago
Edited 3 years ago

It was underlined in red when I wrote this:

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

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

2 answers

Log in to vote
0
Answered by 3 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.

local val = 5 -- player limit

function check()
    if #game.Players:GetChildren() < val then -- # is essentially converting a value in to number.
        return true
    else
        return false
    end
end

game.Players.PlayerAdded:Connect(function()
    local val1 = check() -- getting returned value
    if val1 == true then -- if there are less than 5 players
        -- execute function
        print("Less than 5 players are in")
    else
        print("More than 5 players are in!")
    end
end)
Ad
Log in to vote
0
Answered by 3 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.

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

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

local map1 = game.workspace.Map1
local map2 = game.workspace.Map2
local map3 = game.workspace.Map3
local Players = game.Players
local PlayerNumber = game.Players.PlayerNumber
local playercountdeny = 'not enough players'
if PlayerNumber.Value < 8 then
    print (playercountdeny)

end
0
This will glitch. Did you add a minus 1 function for a person leaving the game? Xapelize 2658 — 3y

Answer this question