Delete Tool on Certain team

So i had been using this script for awhile, but it became very slow to use. and boring.
So this script its proposit, its Deleting a tool when player is on a certain team. But after a while of using it, i would want if its possible to put more than 1 tool instead or multiple teams, because i have doing it for a while and i have many script regarding the same stuff, for example.
Team1 has tool removed “ak-47” and “m9”, and adding new stuff has been a little deprecated. Because my game has like 5 Teams each, and i keep adding the tools to be deleted, sorry if not clear. english is not my main language. Heres is the script.

In short, A way this could be improved in a way that deletes many tools on a certain team if possible or even delete many tools on more than 1 team.

local Team = game:GetService("Teams")["Ciudadanos"]
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if Player.Team == Team then wait(0.5)
			if Character:FindFirstChild("Tool") then
				Character:FindFirstChild("Tool"):Destroy()
			elseif Player.Backpack:FindFirstChild("Tool") then
				Player.Backpack:FindFirstChild("Tool"):Destroy()
			end
		end
		Player.Team.Changed:Connect(function()
			if Player.Team == Team then wait(0.5)
				if Character:FindFirstChild("Tool") then
					Character:FindFirstChild("Tool"):Destroy()
				elseif Player.Backpack:FindFirstChild("Tool") then
					Player.Backpack:FindFirstChild("Tool"):Destroy()
				end
			end
		end)
	end)
end)
1 Like

I don’t think this works, since you can’t specifically check a value and if it has changed.

Well you could possibly as a starter make the Tool change into, something like →

local Tool1 = "Sword"
local Tool2 = "Bat"
local Tool3 = "Katana"

Then for the parts like -

if Player.Team == Team then wait(0.5)
				if Character:FindFirstChild("Tool") then
					Character:FindFirstChild("Tool"):Destroy()
				elseif Player.Backpack:FindFirstChild("Tool") then
					Player.Backpack:FindFirstChild("Tool"):Destroy()
				end
end

You could change it to -

if Player.Team == Team then wait(0.5)
				if Character:FindFirstChild(Tool1,Tool2,Tool3) then
					Character:FindFirstChild(Tool1,Tool2,Tool3):Destroy()
				elseif Player.Backpack:FindFirstChild(Tool1,Tool2,Tool3) then
					Player.Backpack:FindFirstChild(Tool1,Tool2,Tool3):Destroy()
				end
end

But maybe look at tables and arrays? That could possibly be easier.

Seems to work for me, somehow.

You could use GetChildren() if you wanna remove all/some Tools on a certain Team/Player

Heres an example.

local Team = game:GetService("Teams")["Ciudadanos"]
local Players = game:GetService("Players")
local ResistrictedTools = {"Tool1","Tool2"}

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if Player.Team == Team then 
			for i,v in pairs(Player.Backpack:GetChildren()) do
          if table.find(ResistrictedTools,v.Name) then
              v:Destroy()
          end
      end
		end
	end)
end)

I tried it so far, doesn’t seems to work.

Any logged errors in the console?

Nope, nothing so far in the output.

Are you only deleting 1 tool from the player or do you want to restrict multiple tools?

Multiple tools, thats what i made the post for, i have multiple scripts each one for 1 tool for 1 team, they are like 4 tools to remove on 1 team and i have around 5ish teams.

I hope you remembered to edit the restrictedtools table with the correct tool names.

local Team = game:GetService("Teams")["Ciudadanos"]
local Players = game:GetService("Players")
local Restricted = {"ToolName1","ToolName2"}

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if Player.Team == Team then 
			for i,v in pairs(Player.Backpack:GetChildren()) do
          if table.find(Restricted,v.Name) then
              v:Destroy()
          end
      end
		end
	end)
end)

Sorry for late reply, went to sleep and school. The script still seems to not work for me. I might try it on an empty baseplate later. (Nothing on the output)

So are you trying to make team restricted tools? I don’t quite understand

Yeah, that really sums up, i want to a team to not have espefic tools.

Okay so you have 2 options.

Give certain tools on spawn to certain teams

Delete certain tools on teams that aren’t suppose to get it

The first one is easier. Second one is pretty inefficient.

Also the above script does work perfectly fine
Assuming you did change the values correctly.

Alright, it must be something messing up with the code.