Script that Deletes an especific tool if player is on a team

So i want a script that detects if a player changed to a team / spawn on a team, and then delete an especific tool. i really don’t know that much in scripting but atleast i know i have to insert a script that does such thing, any help?

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

if Player.Team == Team then
    -- stuff here
end

(sorry for grammatical issues or spelling english is not my main language.)

I am guessing you would use the destroy function of tool.

https://developer.roblox.com/en-us/api-reference/function/Instance/Destroy

1 Like

is this what you wanted?

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

if Player.Team == Team then
	if Player.Character:FindFirstChild("ToolName") then
		Player.Character:FindFirstChild("ToolName"):Destroy()

	elseif Player.Backpack:FindFirstChild("ToolName") then
		Player.Backpack:FindFirstChild("ToolName"):Destroy()
	end
end
3 Likes

You would not need to do the elseif bit unless you want more then one tool removed/

1 Like

the elseif part is for checking if the tool is in the backpack (unequipped) if the tool isn’t in the character (equipped)

1 Like

Oops yea for a moment I thought you were looking in the same exact place.

1 Like

Doesn’t seems to work for me. “Player” is underline with red.

1 Like

where did you locate the script?

1 Like

ServerScriptService.
(oh well might be my nooby mistake haha)

1 Like

here you go! had to do it so it would find the player and character before checking for the tool

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

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

Doesn’t work for me, i have a auto-team script that teams automatically if you are in group. does that change anything?

forgot to do it so it checks if you’ve changed roles, oops.

pretty sure this one should work

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

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if Player.Team == Team then
			if Character:FindFirstChild("ToolName") then
				Character:FindFirstChild("ToolName"):Destroy()
			elseif Player.Backpack:FindFirstChild("ToolName") then
				Player.Backpack:FindFirstChild("ToolName"):Destroy()
			end
		end
		Player.Team.Changed:Connect(function()
			if Player.Team == Team then
				if Character:FindFirstChild("ToolName") then
					Character:FindFirstChild("ToolName"):Destroy()
				elseif Player.Backpack:FindFirstChild("ToolName") then
					Player.Backpack:FindFirstChild("ToolName"):Destroy()
				end
			end
		end)
	end)
end)

Still doesn’t work, i think because the tool is not deleted because its a gamepasses, maybe it should be moved from a normal script to inside the other script. here is the script of the gamepass giver


local GamepassId = 13267064
local Tool = game.ServerStorage["Knife"]

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
			if Player.Backpack:FindFirstChild("Knife") then

			else
				local ToolClone = Tool:Clone()
				ToolClone.Parent = Player.Backpack
			end

		end
	end)
end)

here you go

local GamepassId = 13267064
local Tool = game.ServerStorage["Knife"]

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, GamepassId) then
			if Player.Backpack:FindFirstChild("Knife") then

			else
				local ToolClone = Tool:Clone()
				ToolClone.Parent = Player.Backpack
			end
		else
		end
	end)
end)

Still… :confused: same problem the knife still there.

Tried on a new baseplate, it still happens.

try adding a wait() before the part where it checks what role you’ve been assigned. not sure if it would work, but it’s worth a try

It worked! thank you so much! IT really helped me.

1 Like