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

Would this script work?

I want GameScript, SithTeamChecker and JediTeamChecker to be enabled when the number of players in the server is 2 or above and if there is only 1 player in the server, the scripts are disabled.

NumberOfPlayers = game.Players.NumPlayers
GameScript = game.Workspace.GameScripts.GameScript
SithTeamChecker = game.Workspace.GameScripts.SithTeamChecker
JediTeamChecker = game.Workspace.GameScripts.JediTeamChecker

while NumberOfPlayers == 0 or 1 do 
    GameScript.Disabled = true
	SithTeamChecker.Disabled = true
	JediTeamChecker.Disabled = true
end

Would this script do this?

Thanks.

1 comment

0

It wouldn't work, but you should always test your code yourself rather than asking others if it will work. It's great for getting in the practice of debugging

1 answer

✓ Accepted answer

There are several issues with this script, for starters game.Players.NumPlayers will only return the current amount of players when you call this to a variable meaning that the NumberOfPlayers will never change. This can easily be solved, also your while loop is a little funky. Rather then using or, you could just use greater than or less than signs. Here is an example of how I would write your code:

GameScript = game.Workspace.GameScripts.GameScript
SithTeamChecker = game.Workspace.GameScripts.SithTeamChecker
JediTeamChecker = game.Workspace.GameScripts.JediTeamChecker

while game.Players.NumPlayers <= 1 do 
    GameScript.Disabled = true
    SithTeamChecker.Disabled = true
    JediTeamChecker.Disabled = true
end

Other then that, I don't see any other major issues. I don't really find your method of managing scripts like this as very efficient but I shall not question your work. If you have any other issues, or questions feel free to ask me at any time!

If this answer helped, make sure to like it and click "Accept Answer" so other users with the same issue can find an answer fast!

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