Hello, recently I’m writing an anti exploit for a game.
The issue is my tool checker code is deleting every tool in players backpack, even some tools are not restricted.
Here is the code:
-------------------
-- ANTI EXTRA TOOLS --
function findRestricted(player)
for i,v in ipairs(player.Backpack:GetChildren()) do
if table.find(game.StarterPack:GetChildren(),v) == nil then
v:Destroy()
end
end
end
----------------------
The issue here is the fact that you’re assuming that the children in the player’s Backpack are the same ones that are in StarterPack, which they are not.
As you probably know doing print(Instance.new("Part") == Instance.new("Part")) will lead to false being outputted, as they are not the same instance. The same logic should be applied to anything that inherits from the Instance class.
In order to fix it, you can do it in a few ways, however, I’m only gonna be showing one.
Instead of using instances to see if the tool is valid and that it is in StarterPack, what if you use the tool name and do StarterPack:FindFirstChild(Tool.Name) to see if it is in StarterPack?
Guess you could just store all the name of RestrictedTools inside a table
local RestrictedTools = {"BanHammer", "Gun"}
for i,v in ipairs(player.Backpack:GetChildren()) do
if table.find(RestrictedTools,v.Name) then
v:Destroy() --destroy the tool when its in the restricted table
end
end