✓ Accepted answer
Hm, so you've given it your best so I'll help you out here. Looking at your variable names, I'm assuming you're going to want to put multiple weapon names in there, so for that you're going to need a table. To go through all of the items in this table, for this task, I'm going to be using the generic for loop (Wiki). After reading up on those, you'll find out the generic for loop is used to go through each index (value/place/item) of a table.
Once you have a for loop setup, I'm going to place it inside a isNotAllowed function to have the script check if the tool name is on the prohibited list. Assuming you're going to want to check the entire player's inventory, you'll have to loop through their backpack as well. Now onto the code: (I've commented it to help you better understand it)
local sound = game.Workspace.scanner.Sound
local prohibitedItems = {"StA-45", "Basic 9mm"}
function isProhibited(name)
local is = false
for _,v in pairs(prohibitedItems) do
if v:lower() == name:lower() then
is = true
end
end
return is
end
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
for _,item in pairs(player:WaitForChild('Backpack'):GetChildren()) do
if isProhibited(item.Name) then
sound:Play()
wait(2)
sound:Stop()
break
end
end
end
end)
1 comment
Edit: Put code in a code block