I’m pretty new to scripting, and I want to create an animated keycard door. When you equip the keycard, the door handle will give you a “Scan” prompt and if you interact with it, the door handle prompt will disappear and a new prompt will appear at the door and will show another prompt saying “Open” for a short time until it gets locked and close again. When the door closes and gets locked again, the “Open” prompt will disappear and prompt “Scan” will reappear on the door handle.
The script worked, but when I try to reopen it again the door went buggy and doesn’t want to open sometimes OR the door will open, but the prompt will show “Close” when the door was already closed. I tried to find the problem and been searching through the DevForum and YouTube tutorials, but I still have no idea what was the cause for this.
Here’s the script (sorry if it’s messy, there are some useless variables in there that I forgot to remove):
local TweenService = game:GetService("TweenService")
local hinge = script.Parent.Hinge
local prompt = script.Parent.ExitDoor.ProximityPrompt
local doorClosed = script.Parent.door_close
local doorOpened = script.Parent.door_open
local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)
local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
local tweenInfo = TweenInfo.new(1)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)
local timeRemaining = 4
local ScanBox = script.Parent.doorhandlee.ProximityPrompt
local debounce = false
local KeyCard = game.ReplicatedStorage.Keycard
-------------------------------------------------------------------
KeyCard.Unequipped:Connect(function()
print("bye")
ScanBox.Enabled = false
end)
KeyCard.Equipped:Connect(function()
print("hello1")
ScanBox.Enabled = true
wait(1)
end)
script.Parent.doorhandlee.ProximityPrompt.Triggered:Connect(function()
if not debounce then
debounce = true
prompt.Enabled = true
prompt.Triggered:Connect(function()
if prompt.ActionText == "Open" then
tweenOpen:Play()
doorOpened:Play()
prompt.ActionText = "Close"
wait(1)
else
tweenClose:Play()
doorClosed:Play()
prompt.ActionText = "Open"
wait(4)
tweenClose:Play()
prompt.Enabled = false
ScanBox.Enabled = false
wait(7)
debounce = false
end
end)
end
end)
1 Like
I found a mistake made in the code. Look at the comments added by me. I might wrong, but it makes much sense.
local TweenService = game:GetService("TweenService")
local hinge = script.Parent.Hinge
local prompt = script.Parent.ExitDoor.ProximityPrompt
local doorClosed = script.Parent.door_close
local doorOpened = script.Parent.door_open
local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)
local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
local tweenInfo = TweenInfo.new(1)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)
local timeRemaining = 4
local ScanBox = script.Parent.doorhandlee.ProximityPrompt
local debounce = false
local KeyCard = game.ReplicatedStorage.Keycard
-------------------------------------------------------------------
KeyCard.Unequipped:Connect(function()
print("bye")
ScanBox.Enabled = false
end)
KeyCard.Equipped:Connect(function()
print("hello1")
ScanBox.Enabled = true
wait(1)
end)
script.Parent.doorhandlee.ProximityPrompt.Triggered:Connect(function()
if not debounce then
debounce = true
prompt.Enabled = true
prompt.Triggered:Connect(function()
if prompt.ActionText == "Open" then
tweenOpen:Play()
doorOpened:Play()
prompt.ActionText = "Close"
wait(1)
-- No setting debounce back to false when opening the door?
else
tweenClose:Play()
doorClosed:Play()
prompt.ActionText = "Open"
wait(4)
tweenClose:Play()
prompt.Enabled = false
ScanBox.Enabled = false
wait(7)
debounce = false -- Setting debounce back to false only when closing the door?
end
end)
end
end)
1 Like
Thank you for helping, but the results are still the same.
Can you try unequipping and equipping the tool before trying to reopen the door?
1 Like
The results are still the same, sadly.
It might be the prompt’s scripting fault:
local TweenService = game:GetService("TweenService")
local hinge = script.Parent.Hinge
local prompt = script.Parent.ExitDoor.ProximityPrompt
local doorClosed = script.Parent.door_close
local doorOpened = script.Parent.door_open
local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)
local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
local tweenInfo = TweenInfo.new(1)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)
local timeRemaining = 4
local ScanBox = script.Parent.doorhandlee.ProximityPrompt
local debounce = false
local KeyCard = game.ReplicatedStorage.Keycard
-------------------------------------------------------------------
KeyCard.Unequipped:Connect(function()
print("bye")
ScanBox.Enabled = false
end)
KeyCard.Equipped:Connect(function()
print("hello1")
ScanBox.Enabled = true
wait(1)
end)
ScanBox.Triggered:Connect(function()
if not debounce then
debounce = true
prompt.Enabled = true
prompt.Triggered:Connect(function() -- The prompt needs to be enabled to work
if prompt.ActionText == "Open" then
tweenOpen:Play()
doorOpened:Play()
prompt.ActionText = "Close"
wait(1)
else
tweenClose:Play()
doorClosed:Play()
prompt.ActionText = "Open"
wait(4)
tweenClose:Play()
prompt.Enabled = false -- Disabling the prompt
ScanBox.Enabled = false
wait(7)
end
debounce = false
ScanBox.Enabled = true
print("Ready to open/close")
-- I don't see anywhere enabling the prompt so reopening won't work
end)
end
end)
1 Like
Sorry for late reply. It kind of worked, but now the door either switches its prompt (Open turned to Close and vice versa) or the duration of the prompt being enabled was too quick.
The door works well now, the problem is mostly on the prompt.
Try to add debounce for the prompt.
1 Like
It worked now! Even though it needs some time so it can work correctly, it’s alright. Thank you!