code:
local teams = game:GetService("Teams"):GetTeams() local teams = game:GetService("Teams"):GetTeams() local function touched (hit) local playing = game.Teams.Playing print(#playing) if #playing:GetPlayers() == 0 then for _, player in pairs(game.Players:GetPlayers()) do player.TeamColor = BrickColor.new('Navy blue') player.Character.Head:Destroy() print('k') end end end script.Parent.Touched:Connect(touched)
error:
Workspace.s.Script:6: attempt to get length of local 'playing' (a userdata value)
the purpose for this script is when you hit a brick then it will restart the match if there are no players on the playing team.
game.Teams.Playing
doesn't return a table. You made an error on line 6, and the solution was right in front of you on line 7. Line 7:
if #playing:GetPlayers() == 0 then
you just have to use :GetPlayers()
to get the amount of players on the Team, and then use # to get the length of the table. Corrected:
local teams = game:GetService("Teams"):GetTeams() local teams = game:GetService("Teams"):GetTeams() local function touched (hit) local playing = game.Teams.Playing print(#playing:GetPlayers()) if #playing:GetPlayers() == 0 then for _, player in pairs(game.Players:GetPlayers()) do player.TeamColor = BrickColor.new('Navy blue') player.Character.Head:Destroy() print('k') end end end script.Parent.Touched:Connect(touched)
You obviously can't get the length of that userdata value, but you can get the length of a table, so use :GetPlayers()
which returns a table of all of the players. That was sorta like a typo.
If that worked, plaese accept my answer \ if it didn't, leave a comment and let me know or if you're confused on something
The '#' operator is used to get the index count of an array. By the looks of it, 'Playing' is a team instance, which does not define any method to handle a length operator.
I think your intent was to check the length of the array returned by Team:GetPlayers()