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

2 things. 1. Code error 2 Help to make a code for to custom make a model for a certain team?

Hello. First thing, This is a alt account if you are wondering why the bacon hair. Other words on to the issue.

First issue.

local teams = game:GetService("Teams")
local tInfo = {
    ["Stalker"] = {
        MaxPlayers = 1;
    }
    ["Survivor"] = {
        MaxPlayers = 9;
    }
    ["Spectator"] = {
        MaxPlayers = 10;
    }
  }

local function countTeam(team)
    local count = 0
    for _, player in next, players:GetPlayers() do
        if player.Team == team then
            count = count + 1
        end
    end
    return count
end

local function assignRandomTeam(player)
    local assigned = false
    while not assigned do
        local randomTeam = teams:GetChildren()[math.random(#teams:GetChildren())]
        if randomTeam and countTeam(randomTeam) < tInfo[randomTeam.Name].MaxPlayers 
then
            player.Team = randomTeam
            assigned = true
        end
        wait(.5)
    end
end
	

Is the code i have to randomly select a player to a team. It was from a dev forum(Cant find it again). Also about how many people get in a team. When i run the command. It dose not randomize. it also gives me this error.

Workspace.Script Error 96,50 Expected ') (to close '{' at line 2),got '['

Also where do i place this. Do i keep it in the workshop or move it to a new file.

2 thing. Basically the title. i need some help creating a code that when a player joins a team they will be remodeled to a model i have.

Thank you.

1 answer

Add commas to the first tables contents

local tInfo = {
    ["Stalker"] = {
        MaxPlayers = 1;
    },
    ["Survivor"] = {
        MaxPlayers = 9;
    },
    ["Spectator"] = {
        MaxPlayers = 10;
    }
  }

And for the random team replace it with

local randomTeam = teams:GetChildren()[math.random(1,#teams:GetChildren())]

3 comments

0

The comma's fixed the error. But for the local randomTeam. I replaced that on line 27 but it will still not do a randomize

0

Are you calling the function and is this a normal script

0

It was a normal script i changed it to a local. Still doesn't work. Im new to coding so what you you mean calling on the function.

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