I need help, I have a game and I want to have a script that kicks them from a team. I have a script to auto make a team have equal players on two teams but I need a way to transition to the lobby to one of those teams. This is my script. I understand why it doesn’t work but can someone help me with a script?
If you want to kick someone out of a team, you should either assign him to a different team, or make sure he will be assigned to a natual team with a spawnpoint. To change someone’s team, you can simply do "player.Team.TeamColor = BrickColor.new("ChooseColorHere)
EDIT: I agree with @Forummer , he gave you a better way to do that. At the time I was typing that reply, I was on bus, and couldn’t provide a better reply, but hopefully @Forummer 's explanation satisifed you.
You solved half of the problem I solved the other half. Thanks for the color idea!
The Team
property of a player instance should be assigned instead. Bare in mind, players also have a TeamColor
property.
It is advised not to assign to this property however as it necessitates the creation of a BrickColor value.
https://developer.roblox.com/en-us/api-reference/property/Player/TeamColor
Team kick script:
local teams = game:GetService("Teams")
local function kickPlayerFromTeam(player) --Function which requires a player instance.
local _teams = teams:GetTeams() --Get an array of teams.
table.remove(_teams, table.find(_teams, player.Team)) --Remove player's team from pool of teams.
player.Team = _teams[math.random(#_teams)] --Assign player to a random team.
end
Team balancer script:
local players = game:GetService("Players")
local teams = game:GetService("Teams")
local team1 = teams.Team1 --Example team.
local team2 = teams.Team2 --Example team.
local _teams = {team1, team2}
local function randomiseBalancedTeams()
for _, player in ipairs(players:GetPlayers()) do
if #team1:GetPlayers() > #team2:GetPlayers() then
player.Team = team2
elseif #team1:GetPlayers() < #team2:GetPlayers() then
player.Team = team1
else
player.Team = _teams[math.random(#_teams)]
end
end
end