Script not destroying tool because its being auto equipped

So I have a script that deletes newly added tools, however it doesnt work sometimes because when I pick up a tool it auto-equips which means it goes to the character first instead of the backpack which means it won’t get deleted. Yes I have tried if anything is added to the character but that just makes it so when you equip the tool it gets deleted. Please Help.

local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local backpack = player:WaitForChild("Backpack")

local function randNum()
	return math.random(-4, 4)
end

backpack.ChildAdded:Connect(function(child)
	local toolCount = #backpack:GetChildren()
	if toolCount > 1 then
		child:Destroy()
	end
end)

player.Character.ChildAdded:Connect(function(child)
	local toolCount = #backpack:GetChildren()
	if child:IsA("Tool") then
		wait(0.5)
		if toolCount > 1 or toolCount == 1 then
			child:Destroy()
		end
	
	end
end)

thanks

local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local backpack = player:WaitForChild("Backpack")

local function randNum()
	return math.random(-4, 4)
end

backpack.ChildAdded:Connect(function(child)
	local toolCount = #backpack:GetChildren()
	if toolCount > 1 then
		child:Destroy()
	end
end)




local Char = player.Character or player.CharacterAdded:wait()

local Tools = {}

for I, v in pairs(player.Backpack:GetChildren()) do
	Tools[v] = true
end

Char.ChildAdded:connect(function(Obj)
	if Obj:IsA("Tool") and not Tools[Obj] then
		Tools[Obj] = true
		Obj.Parent = player.Backpack
	end
end)

this worked…

image
image
image

can bro decide?!

1 Like

mb it sometimes happens when i mix 2 scripts together into a serverscript.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.