Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years 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:

01slider = script.Parent.Model.touchz
02acceptedsound = script.Parent.accepted
03declinedsound = script.Parent.declined
04 
05local openClick = game.Workspace.DoorButton1.fart.ClickDetector
06local tweenService = game:GetService("TweenService")
07local Properties = {
08    Position = Vector3.new(-198.327, 12.12, 71.057)
09}
10local TweenInfoo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
11local tween = tweenService:Create(script.Parent,TweenInfoo,Properties)
12local Properties2 = {
13    Position = Vector3.new(-198.287, 4.39, 71.057)
14}
15local TweenInfooo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
View all 25 lines...

This is probably what is wrong with the script:

1slider.ClickDetector.MouseClick:Connect(function(player)
2    if player.Backpack:FindFirstChild("Keycard") then
3        tween:Play()
4        acceptedsound:Play()
5    else
6        declinedsound:Play()
7    end
8end)

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 — 2y
0
does it play the declined sound? BulletproofVast 1033 — 2y
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 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

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

01slider = script.Parent.Model.touchz
02acceptedsound = script.Parent.accepted
03declinedsound = script.Parent.declined
04 
05local openClick = game.Workspace.DoorButton1.fart.ClickDetector
06local tweenService = game:GetService("TweenService")
07local Properties = {
08    Position = Vector3.new(-198.327, 12.12, 71.057)
09}
10local TweenInfoo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
11local tween = tweenService:Create(script.Parent,TweenInfoo,Properties)
12local Properties2 = {
13    Position = Vector3.new(-198.287, 4.39, 71.057)
14}
15local TweenInfooo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
View all 25 lines...

if this works please approve this ty

Ad

Answer this question