Hi, I was making a team randomization script for my game, and none of the ones I tried on the internet worked. So I worked up from the basics of randomizing numbers to where I am now. Here's my code
local random = math.random(1,4)
local player = game.Players:GetPlayers()
if random <= 3 then
player.Team = game.Teams.TeacherBlu
player.TeamColor = game.Teams.TeacherBlu.TeamColor
elseif random == 4 then
print("Didthiswork")
end
So this script is being called on and functioning because when I run the game the output has a 1/4 chance of printing "didthiswork". So the randomization is working. But if I get a value greater than or equal to three then nothing happens. My character doesn't switch teams, it doesn't spit out an error, nothing. So I've deduced that this stems from a problem with the game trying to put the player into a team. The problem is, I don't know what I'm doing wrong. can anyone tell me what's wrong with this part of the script? Thanks in advance.
player.Team = game.Teams.TeacherBlu
player.TeamColor = game.Teams.TeacherBlu.TeamColor

3 comments
@OfficerBrah Sorry but I tried your script and now the script doesn't even run. I'm not seeing anything in the output and my teams have not been randomized. Could I be doing something wrong, just for the record I'm using a regular standard script(not a local or module script) and I'm putting that script in my workplace
Scripts run as soon as the server is started, before the player has a chance to join, so the code will do nothing because there are no players in the game. That would be how you set random teams at the end of a countdown or something, but you can use the PlayerAdded event to randomize someone's team as soon as they join
Thanks man, it worked, Idk where I'd be without you. I've been working on this for 3 three days and every path has been a dead end until now. Couldn't thank you enough.