So Im making a roblox darkrp and I need to limit it to 1- 6 player for that team, How exactly would I script this?
wont work
So Im making a roblox darkrp and I need to limit it to 1- 6 player for that team, How exactly would I script this?
wont work
Assuming autoassignable is off you can do something like this.
if #game.Teams["Team Name"]:GetPlayers() < 6 then
-- plr.TeamColor = Team Name.TeamColor or BrickColor.new("name")
-- or
-- plr.Team = game.Teams["Team Name"]
eles
-- team full
end
It’s GetPlayers, not GetPlayer. If you’re trying to get the number of people on a team, then call it and use the length operator to get the number of elements in the array of players (in short: how many people are on that team). If it exceeds a maximum you want, reject the client’s team change request.
For example:
local Teams = game:GetService("Teams")
local TEAM_CAPS = {
["Mayor"] = 1,
-- If you're lazy, you can use math.huge for uncapped teams
}
teamChangeEvent.OnServerEvent:Connect(function (player, teamName)
local team = Teams:FindFirstChild(teamName)
if team then
-- Guard clause, don't know how many checks you'd actually need
if TEAM_CAPS[teamName] and #team:GetPlayers() >= TEAM_CAPS[teamName] then
return
end
player.Team = team
end
end)