Tool won't remove from table

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to create an ability which allows a player to use another persons ability in a 20 stud radius.

  2. What is the issue? Include screenshots / videos if possible!
    When trying to remove a tool in the table, it doesn’t remove for some reason.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried several different methods of fixing it. However it doesn’t remove it anyway I try to fix it.

The ability used to take other abilities is called Skill Hunter, which is the ability that won’t be removed, even when it’s equipped or unequipped it doesn’t change anything (the ability is a gui in a tool so it can be used while another ability is being used). I believe it has something to do with Skill Hunter being the first item in the table but I don’t know, here’s the script, if you need any more info about it when please tell, thanks!

local rscavenge = game.ReplicatedStorage.RemoteEvents.AbilityEvents.BookScavenge

local module = require(game.ReplicatedStorage.Framework.Server.ComponentModule)

rscavenge.OnServerEvent:Connect(function(plr)
	local nearp = module.locatenearest(plr, 20)
	print(nearp)
	local available = {}
	local selecteda
	for i,v in pairs(nearp.Backpack:GetChildren()) do
		if v:FindFirstChild("Cooldown") and v:FindFirstChild("Main") and not v:FindFirstChild("UA") then
			table.insert(available, v)
		end
	end
	for i,v in pairs(nearp.Character:GetChildren()) do
		if v:FindFirstChild("Cooldown") and v:FindFirstChild("Main") and not v:FindFirstChild("UA") then
			table.insert(available, v)
		end
	end
	print(available)
	for i,v in pairs(available) do
		if plr.Character:FindFirstChild(v.Name) or plr.Backpack:FindFirstChild(v.Name) then
			table.remove(available, table.find(available, v.Name))
		end
	end
	print(available)
	if available ~= {} then
		selecteda = available[math.random(#available)]
		
		local sc = selecteda:Clone()
		sc.Parent = plr.Backpack
	else
		print("no more abs found")
	end
end)

I fixed this by setting the table to {} if there was 1 object that is already in the player, it does register as beinbg in the player but it just decides not to remove it

When you are adding the tool to the table, you are adding the object

table.insert(available, v)

However, when you are trying to find it in the table, you are finding the object’s name.

Replace

table.remove(available, table.find(available, v.Name))

with

table.remove(available, table.find(available, v))

and see if it resolves the issue.
If it doesn’t work as intended, you can try reverting that particular change and instead replace v with v.Name in earlier in the script when you insert them into the table

I already found a fix, however doing this makes it no longer work.

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