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

My script to enable teleporter if there are 2 or more players isn't working?

Asked by 7 years ago
local amountOfPlayers = game.Players.NumPlayers

while true do
    if amountOfPlayers >= 2 then
        game.Workspace.Lobby.Teleporters.TeleporterA.Teleporter1.Script.Disabled = false --turns the teleporter off
        print("Enough Players")
        print(amountOfPlayers)
        wait(10)
    else 
        game.Workspace.Lobby.Teleporters.TeleporterA.Teleporter1.Script.Disabled = true --turns teleporter on
        print("Not Enough Players")
        print(amountOfPlayers)
        wait(10)
    end
end

I am making a game with 3 teleporters and I want it so when there is 2 or more players the teleporters will be enabled. When I run the game by myself I get not enough players like a should but it also prints 0. It does the same with 2 players.

0
No one else is playing. So NumPlayers is 0. mightydifferent 85 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

"amountOfPlayers" will always be whatever the value first assigned to it is. Try putting it inside of your loop, or change the value of it using the .PlayerAdded event.

Ad

Answer this question