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

Player chooser not working correctly?

Asked by 10 years ago

Hello Scripting Helpers! I am working on a game and in one part the game chooses one player randomly and changes his team, this is the script:

function playeer()
math.random(tick())
plr = game.Players:GetPlayers()
    print (math.random(#plr))
    plr.TeamColor = "Really Red"
        wait(1)
        end
wait(23)
playeer()

The output only prints one number, this could be depending on the number of players, for example if theres 5 players it only prints one number which is positive and below 5, and so on like if theres 3 players, it prints a positive number below 3 or it could be 3, but thats the highest it could print due to the number of players. Also it doesn't changes the teamcolor.

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

Your main functionality problem is line 5.

You can't change the TeamColor of a list (which is what plr equals; it's a list of all the players) and even if it wasn't a list, TeamColor is not a string value. There are some other problems, however, even if they won't affect the over-all functionality.

  • Line 2 is completely pointless.

  • Nothing is tabbed correctly.

  • Waiting one second at the end of the function will not accomplish anything unless you were doing something immediately after, which you are not.

  • plr should be a local variable since you don't use it outside that function. This is more efficient.

  • plr is not a good name for that variable, for it is not a specific player, but a list of all the players in the game.

  • playeer as a function name does not make sense considering that you are changing all of the players' TeamColors to really red. The name should be chosen based on what you want to happen.

Here is my improved version of that script;

function changeTeamColors()
    local plrs = game.Players:GetPlayers
    print(math.random(#plrs))

    for index,player in pairs(plrs) do --Loops through the list one at a time
        player.TeamColor = BrickColor.new("Really red")
    end
end
wait(23)
changeTeamColors()
0
I tested it and the output says "16:53:19.834 - Workspace.Script:3: function arguments expected near 'print'" SpaceEnder 5 — 10y
0
never mind found the error, there are missing parenthesis. SpaceEnder 5 — 10y
0
Oh yeah sorry about that. Perci1 4988 — 10y
Ad

Answer this question