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

Is there a way I can destroy this team?

I've been working on this script for a day and I'm still stuck on destroying the team when nobody is on it.

local teams = game.Teams
local random = 0
local teamColor = teams:GetDescendants()
local playerammount = 0
local blueTeam = game.Teams:GetChildren()
local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(player) ---- Creates the teams based off player names and color based on random number
	local newTeam = Instance.new("Team",game.Teams)
	newTeam.Parent = teams
	newTeam.Name = (player.Name .. "'s Factory")
	player.Neutral = false
	playerammount = playerammount + 1
	if playerammount == 1 and newTeam.Name == (player.Name .. "'s Factory") then
		newTeam.TeamColor = BrickColor.new("Really blue")
		player.TeamColor = newTeam.TeamColor
	elseif playerammount == 2 and newTeam.Name == (player.Name .. "'s Factory") then
		newTeam.TeamColor = BrickColor.new("Lime green")
		player.TeamColor = newTeam.TeamColor
	elseif playerammount == 3 and newTeam.Name == (player.Name .. "'s Factory") then
		newTeam.TeamColor = BrickColor.new("Deep blue")
		player.TeamColor = newTeam.TeamColor
	elseif playerammount == 4 and newTeam.Name == (player.Name .. "'s Factory") then
		newTeam.TeamColor = BrickColor.new("Crimson")
		player.TeamColor = newTeam.TeamColor
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local Players = game.Players:GetChildren()
	local blueteam = game:GetService("Teams"):getChildren(teamColor.TeamColor == BrickColor.new("Really blue"))
	if player.TeamColor == BrickColor.new("Really blue") then
	blueTeam:Destroy()
	end
end)

Right now its just returning ServerScriptService.Script:33: attempt to call method 'Destroy' (a nil value). Which from my understand is because its trying to destroy the wrong thing. So basically what I want to know is is there a way i can call the Really blue team and then use :Destroy() on it.

3 comments

1

Nothing in your PlayerRemoving function makes sense. Review it, literally nothing is correct.

0

The blueTeam:Destroy() is not indented

0

Yes lua is python indents matter!! or else ur script died

1 answer

Figured out what was wrong in most of the versions if i was referencing the color i did team.BrickColor == BrickColor.new when it should have been team.TeamColor == BrickColor.new. Here's what i ended up with

game.Players.PlayerRemoving:Connect(function(player)
	local teama = game.Teams:GetDescendants()
	for _,v in pairs(teama) do
		if v.TeamColor == BrickColor.new("Really blue") and v.Name == (player.Name .. "'s Factory")then
			v:Remove()
			playerammount = 0
		elseif v.TeamColor == BrickColor.new("Lime green") and v.Name == (player.Name .. "'s Factory") then
			v:Remove()
			playerammount = 1
		elseif v.TeamColor == BrickColor.new("Deep blue") and v.Name == (player.Name .. "'s Factory") then
		 	v:Remove()
			playerammount = 2
		elseif v.TeamColor == BrickColor.new("Crimson") and v.Name == (player.Name .. "'s Factory") then
			v:Remove()
			playerammount = 3
		end
	end
end)

Also thank you Nowaha for making me rethink how to do it.

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