I think I'm missing something on the logic of this simple auto team set script

Hello guys.

The script is this (It is inside ServerScriptService):

local Players_ = game:GetService(“Players”)

local Teams_ = game:GetService(“Teams”)

local Stage1 = Instance.new(“Team”, Teams_)

Players_.PlayerAdded:Connect(function(plr)

plr.Neutral = false

plr.Team = Stage1

plr.TeamColor = BrickColor.new(“Ghost grey”)

end)

local BrickTable = {“Bright red”, “Persimmon”, “Pine Cone”, “Deep orange”, “Light blue”, “Really black”, “Cyan”, “Linen”, “Hot pink”}

local StageNumber = 2

local StageCounter = 1

local BrickTableIndex = 1

local TeamsArray = {}

Stage1.AutoAssignable = true

Stage1.Name = “Stage 1”

Stage1.TeamColor = BrickColor.new(“Ghost grey”)

while StageCounter <=9 do

TeamsArray[#TeamsArray+1] = Instance.new(“Team”, Teams_)

TeamsArray[#TeamsArray].Name = "Stage " … tostring(StageNumber)

TeamsArray[#TeamsArray].TeamColor = BrickColor.new(BrickTable[BrickTableIndex])

BrickTableIndex = BrickTableIndex + 1

StageCounter = StageCounter + 1

StageNumber = StageNumber + 1

end

The result should be that I would have Teams with the names of stages 1 to 10 but this happens instead:

image

It used to work, but somewhere in an unspecified time in space I changed something that broke it and I don’t even think the change was within that script!

Please help me, I’ve been trying to debug this for awhile but I’m clearly missing something.

Hey robloxfoda1!

I’ve made some changes to your script and I’ve came out with the script which I pasted below.

local Teams_ = game:GetService("Teams")

local Stage1 = Instance.new("Team", Teams_)

local BrickTable = {“Bright red”, “Persimmon”, “Pine Cone”, “Deep orange”, “Light blue”, “Really black”, “Cyan”, “Linen”, “Hot pink”}
local StageNumber = 2
local StageCounter = 1
local BrickTableIndex = 1
local TeamsArray = {}

Stage1.AutoAssignable = true
Stage1.Name = "Stage 1"
Stage1.TeamColor = BrickColor.new("Ghost grey")

while StageCounter <=9 do

    local tm = Instance.new(“Team”, Teams_)
    table.insert(TeamsArray, tm)

    tm.Name = "Stage "..tostring(StageNumber)
    tm.TeamColor = BrickColor.new(BrickTable[BrickTableIndex])

    BrickTableIndex = BrickTableIndex + 1
    StageCounter = StageCounter + 1
    StageNumber = StageNumber + 1
end

As there might be some mistakes, but I think mine version looks better and it might fix your issue as well.

First thing that I have done was removing the Player added part, as I found it having no reason to be there, because the team is AutoAssignable, so the player’s team will be changed to it automatically.

Second thing that I’ve done was formating. The script that you’ve posted here was really hard for me to read, so I made it look somewhat better.

Third thing that I’ve done was creating a variable when making a team in the while loop. The method that you used was a little bit messy.

As I’ve read the script some times, there might still be some issues about it, so please get back to us with new results.

1 Like

First off thanks for your time. I just wanna address that the playeradded was there because there was a weird bug where I spawned in a totally unrelated spawnlocation so I did that to reinforce the team and it worked. And about the formating, it was better I just messed up when I submited it here, I don’t know why the devforum did that, I don’t submit much code here. Also, here comes the weird part of this all: After I posted this, I went to sleep and now when I came back and tested my file which was producing that, the script worked just as before, everything working fine. With that in mind, I think your script probably works very well (I didn’t test it as mine is working just as fine now) and is way better than mine but I’m just extremely weirded out as to why all of that happened.

Now, it actually seems like I’m accesing a rollback, this is really frustrating too because I vividly remember saving my progress and this happens frequently where I do Ctrl+S, quit and then when I come back I lost my progress.