I’m making a door but the problem is that the script stops working entirely if I try to use the key. Any help?
-- relevant part
local locked = true
local isOpen = false
local debounce = false
local requiredKey = "Key (Room A)"
local function Clicked(player)
if debounce then return end
local Character = player.Character
local foundKey = player.Character:FindFirstChild(requiredKey)
print(player.Name.." Interacted: "..door.Name)
if locked then
debounce = true
if foundKey then
print("Tool Found")
foundKey:Destroy()
locked = false
print("locked: "..locked)
else
print("Couldn't find key!!!")
end
hasInteracted:FireClient(player, locked)
elseif not locked then
debounce = true
if isOpen == false then
doorOpen:Play()
isOpen = true
doorOpen.Completed:Wait()
debounce = false
else
doorClose:Play()
isOpen = false
doorClose.Completed:Wait()
debounce = false
end
end
end
clickDetector.MouseClick:Connect(Clicked)
To mention: It only stops working once I have my tool equipped, and works again when unequipped