I have a scanning system to check for illegal tools in a player's backpack and it works it just doesn't remove the players that have been displayed from the table. I need help to fix this:
It does remove but it gives a bunch of messages: [SUSPECTSHOT108]: ARMED when it should give one then remove the player's name from the table.
Server Script:
local touched = {} local detectable = {'G18', 'G17', 'M-18', 'Minigun', 'Sword'} local function SearchTable(tab, val) local bool = false for _,v in ipairs(tab) do if v == val then bool = true end end return bool end script.Parent.Touched:Connect(function(hit) local Player pcall(function() Player = game.Players:GetPlayerFromCharacter(hit.Parent) end) if Player then if SearchTable(touched, Player.Name) == true then return else table.insert(touched, Player.Name) end end for i,v in pairs(touched) do local target = game.Players:FindFirstChild(v) print (target.Name..' is in the table!') for _,d in pairs(detectable) do print (d..' can be detected!') if target.Backpack:GetChildren() == nil then return end for _,t in pairs(target.Backpack:GetChildren()) do if t.Name == d then local Clone = script:WaitForChild("Example"):Clone() local Name = string.upper(target.Name) Clone.Text = "["..Name.."]: ARMED" Clone.TextColor3 = Color3.fromRGB(255, 0, 0) Clone.Parent = script.Parent.Parent.Status.Text.Frame print (target.Name..' is armed!') table.remove(touched, i) -- %Remove% else local Clone = script:WaitForChild("Example"):Clone() local Name = string.upper(target.Name) Clone.Text = "["..Name.."]: ARMED" Clone.Parent = script.Parent.Parent.Status.Text.Frame print (target.Name..' is unarmed!') table.remove(touched, i) -- %Remove% end end end end end)
Alright, I fixed it! If you are wondering how:
local touched = {} local detectable = {'G18', 'G17', 'M-18', 'Minigun', 'Sword'} local cooldown = false local function SearchTable(tab, val) local bool = false for _,v in pairs(tab) do if v == val then bool = true break end end return bool end local function AddLabel(target, d, t) if t == 'armed' then local Clone = script:WaitForChild("Example"):Clone() local Name = string.upper(target.Name) Clone.Text = "["..Name.."]: ARMED | DETECTED: "..d Clone.TextColor3 = Color3.fromRGB(255, 0, 0) Clone.Parent = script.Parent.Parent.Status.Text.Frame else local Clone = script:WaitForChild("Example"):Clone() local Name = string.upper(target.Name) Clone.Text = "["..Name.."]: UNARMED | DETECTED: "..d Clone.Parent = script.Parent.Parent.Status.Text.Frame end end script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("HumanoidRootPart") then if not cooldown then cooldown = true local Player pcall(function() Player = game.Players:GetPlayerFromCharacter(hit.Parent) end) if Player then if SearchTable(touched, Player.Name) == true then return else table.insert(touched, Player.Name) end end for i,v in pairs(touched) do local target = game.Players:FindFirstChild(v) table.remove(touched, i) for _,d in pairs(detectable) do if target.Backpack:GetChildren() == nil then return end for _,t in pairs(target.Backpack:GetChildren()) do if t.Name == d then AddLabel(target, d, 'error') break --[[elseif t.Name ~= d then AddLabel(target, d, 'unarmed') break]] end end end end wait(4) cooldown = false end end end)