local function getTeamPlayers(teamColor) local output = {} for _, player in pairs(game.Players:getPlayers()) do if (not player.Neutral) and player.TeamColor == BrickColor.new(teamColor) then table.insert(output, player) end end return output end length = function( tab ) local count = 0 -- increases in accordance with --number of entries in provided table for index, value in next, tab do -- iterates through provided table count = count + 1 end return count -- returns total amount of found entries in table `tab` end length(getTeamPlayers()) function onClicked() print "test" -- To test if it even gets up to this point if (#getTeamPlayers("Bright blue")) < 17 then print(#getTeamPlayers("Bright blue")) game.Players.LocalPlayer.TeamColor = BrickColor.new("Bright blue") -- This is the broken line end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
The line to change a player's team isn't working. I have tried lots and lots and things and now I have no idea. How do I change the player who pressed team to Bright blue?
Hi.
The length function I gave was just an example of how the operator itself functioned. It wasn't really meant to be used in your code because the operator is much easier and simpler to use.
You cannot use the LocalPlayer
unless you are running your code from a LocalScript
.
You might also want to check that the player's Neutral
property is set to false so that they can be automatically classed under the blue team on the leader-board.
local player = game.Players.LocalPlayer -- assign a variable to the local player local function getTeamPlayers(teamColor) local output = {} for _, v in pairs(game.Players:getPlayers()) do if (not v.Neutral) and v.TeamColor == BrickColor.new(teamColor) then table.insert(output, player) end end return output end local function onClicked() if (#getTeamPlayers("Bright blue")) < 17 then if player.Neutral then player.Neutral = false end player.TeamColor = BrickColor.new("Bright blue") end end script.Parent.ClickDetector.MouseClick:connect(onClicked)