I am building a ticket scanner system for my game. I have a script that approves or declines entry through a scanner depending on the tool the player is holding. However, the scanners seem to randomly break and refuse to accept any .Touched events.
Script:
local allowedTicketNames = {
"Ticket"
}
local opener = require(script.Parent.Parent.ManageDoor)
local debounce = false
script.Parent.Touched:Connect(function(part)
if debounce == false then
debounce = true
print("touched")
local toolExists = nil
if part.Parent:FindFirstChildOfClass("Tool") then
toolExists = part.Parent:FindFirstChildOfClass("Tool")
elseif part:IsA("Tool") then
toolExists = part
elseif part.Parent:IsA("Tool") then
toolExists = part.Parent
end
if toolExists then
print("tool detected")
if table.find(allowedTicketNames,toolExists.Name) then
print("approved")
opener:ApproveEntry()
else
print("declined")
opener:EntryDeclined()
end
end
task.wait(0.125)
debounce = false
end
end)