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)

15 comments
Your uncertainty is correctly placed; you're not using
table.removeproperly. The second argument is always the position in the array that you want to remove; not the value in it's place.Instead, it should be
table.remove(touched, i)Ok, I will try it
Ok, I edited it. It might be removing it from the table, but it gives a bunch of [SUSPECTSHOT108]: ARMED I need it to only do that once and then remove the name.
Its doing it once per item, as it should.
.----------. oof But it gives about 15 messages per item, whenever it should give 1.
It shouldnt be? If the script is working as it should be just remove the print, its just for troubleshooting anyway.
Do you know where I could add a debounce in this?
Do you want this to completely stop once it finds something?
Alright, I'm gonna add a break
Yeah, whenever it finds something, stops.
Thats what i was gonna recommend, a break on line... 42? That sounds good.
It still displays to many messages.
Alright, I fixed it. Thank you.
:GetChildren() wont be nil, it will just be an empty table btw. and u dont need to use pcall to find the player. just run an if statement to make sure it isnt nil