Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

1 comment

0

No one else is playing. So NumPlayers is 0.

1 answer

✓ Accepted answer

"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.

This discussion is preserved as it was. New answers, comments, and votes are closed.