I was trying to make a script that when the player equip the tool, it will change the prompt’s text to “unlock”, and the door will check if the action text is “unlock”, if it is, then it will unlock the door. The problem is that I want to unlock and open the door when lockpick is being held, however, it didn’t work, please help. (Both scripts are local script)
Here is the entire script for the door:
local tween = game:GetService("TweenService")
for _,door in pairs(game.Workspace:GetDescendants()) do
if door:IsA'Model' then
if door.Name == "Door" then
local prompt = door.Base.ProximityPrompt
local locked = door.Locked
local hinge = prompt.Parent.Parent.Doorframe.Hinge
local openandclose = script["Open/Close"]
local locksound = script.Locked
local player = game.Players.LocalPlayer
local text = player.PlayerGui:WaitForChild("Text").StatusText
local trans = text.TextTransparency
local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(45), 0)
local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
local goalfade = {}
TextTransparency = 1
local Info = TweenInfo.new(1)
local fadeinfo = TweenInfo.new(3)
local Open = tween:Create(hinge, Info, goalOpen)
local Close = tween:Create(hinge, Info, goalClose)
--local Fade = tween:Create(trans,fadeinfo,goalfade) --still figuring why this creates an error
prompt.Triggered:Connect(function()
if locked.Value == true then
if prompt.ActionText ~= "Unlock" then
locksound:Play()
text.TextTransparency = 0
--Fade:Play()
---Next 3 lines are a temporary replacement of "Fade"
text.Text = "The door is locked."
wait(5)
text.TextTransparency = 1
elseif prompt.ActionText == "Unlock" then
locked.Value = false
Open:Play()
openandclose:Play()
prompt.ActionText = "Close"
prompt.HoldDuration = 1
prompt.Enabled = false
wait(1)
prompt.Enabled = true
end
else
if prompt.ActionText == "Close" then
Close:Play()
openandclose:Play()
prompt.ActionText = "Open"
prompt.Enabled = false
wait(1)
prompt.Enabled = true
else
Open:Play()
openandclose:Play()
prompt.ActionText = "Close"
prompt.Enabled = false
wait(1)
prompt.Enabled = true
end
end
end)
end
end
end
And here is the script for the tool:
local tool = script.Parent
tool.Equipped:Connect(function()
for _,door in pairs(game.Workspace:GetDescendants()) do
if door:IsA'Model' and door.Name == "Door" then
local locked = door.Locked
local prompt = door.Base.ProximityPrompt
if locked.Value == true then
prompt.HoldDuration = 5
prompt.ActionText = "Unlock"
end
end
end
end)
tool.Unequipped:Connect(function()
for _,door in pairs(game.Workspace:GetDescendants()) do
if door:IsA'Model' and door.Name == "Door" then
local locked = door.Locked
local prompt = door.Base.ProximityPrompt
if locked.Value == true then
prompt.HoldDuration = 0
prompt.ActionText = "Open"
end
end
end
end)