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

Would this script work?

Asked by
Avectus 120
9 years ago

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.

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 DigitalVeer 1473 — 9y

1 answer

Log in to vote
1
Answered by
Bman8765 270 Moderation Voter
9 years ago

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!

Ad

Answer this question