0

# Door system always doesn't open with or without a keycard in the backpack?

Edited 1 month ago

Hello!

Let's cut to the chase, I am attempting to make a keycard system in which you have to click the keycard scanner with a keycard in your backpack.

(I did this instead of having to check for a keycard in their character, because apparently clickdetectors don't work with tools on)

Now, there are no errors or anything. Even with the keycard in the playres backpack, it will always deny access (play a denied sound and not open the door) and I seriously need help.

Here's the code:

slider = script.Parent.Model.touchz
acceptedsound = script.Parent.accepted
declinedsound = script.Parent.declined

local openClick = game.Workspace.DoorButton1.fart.ClickDetector
local tweenService = game:GetService("TweenService")
local Properties = {
Position = Vector3.new(-198.327, 12.12, 71.057)
}
local TweenInfoo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
local tween = tweenService:Create(script.Parent,TweenInfoo,Properties)
local Properties2 = {
Position = Vector3.new(-198.287, 4.39, 71.057)
}
local TweenInfooo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
local tween2 = tweenService:Create(script.Parent,TweenInfooo,Properties2)

slider.ClickDetector.MouseClick:Connect(function(player)
if player.Backpack:FindFirstChild("Keycard") then
tween:Play()
acceptedsound:Play()
else
declinedsound:Play()
end
end)


This is probably what is wrong with the script:

slider.ClickDetector.MouseClick:Connect(function(player)
if player.Backpack:FindFirstChild("Keycard") then
tween:Play()
acceptedsound:Play()
else
declinedsound:Play()
end
end)



https://cdn.discordapp.com/attachments/1076530438912356392/1076817600698396682/image.png

A picture of the tools in the backpack, in case that would help.

Thank you in advance for helping!

edit: forgot to include .MouseClick

0
What is openClick being used for? Add some debugging with print statements.  GuestRealization 102 — 1mo
0
does it play the declined sound? BulletproofVast 1033 — 1mo
0
I fixed it not playing. The only thing is, when you are holding the tool clicking the keycard slider doesn't work. EricAndTheWell 11 — 1mo

1

its probably not playing because when you hold an item in your hand, it gets removed from the backpack and put into the player's character. so I recommend adding player.Character to line 19 (If you want it to open only if your holding the item and not in the backpack just remove player.Backpack:FindFirstChild("Keycard")

Script

slider = script.Parent.Model.touchz
acceptedsound = script.Parent.accepted
declinedsound = script.Parent.declined

local openClick = game.Workspace.DoorButton1.fart.ClickDetector
local tweenService = game:GetService("TweenService")
local Properties = {
Position = Vector3.new(-198.327, 12.12, 71.057)
}
local TweenInfoo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
local tween = tweenService:Create(script.Parent,TweenInfoo,Properties)
local Properties2 = {
Position = Vector3.new(-198.287, 4.39, 71.057)
}
local TweenInfooo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
local tween2 = tweenService:Create(script.Parent,TweenInfooo,Properties2)

slider.ClickDetector.MouseClick:Connect(function(player)
if player.Backpack:FindFirstChild("Keycard") or player.Character:FindFirstChild("Keycard") then
tween:Play()
acceptedsound:Play()
else
declinedsound:Play()
end
end)


if this works please approve this ty