Door lock script dont work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Make my door lock script work
  2. What is the issue? Include screenshots / videos if possible!
    my script get a error " attempt to call a nil value "
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    its a pretty specific thing that i would probally not be able to find a answer that easily
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

my script

local proximityprompt = script.Parent.ProximityPrompt
local locked = script.Parent.Parent.locked
local opened = script.Parent.Parent.Opened

if opened.Value == true then
	proximityprompt.Enabled = false
else
	proximityprompt.Enabled = true
	proximityprompt.Triggered:Connect()
	locked.Value = true
	script.Parent.Parent.DoorFrame.Script.Disabled = true
	if locked.Value == true then
		proximityprompt.Triggered:Connect()
		locked.Value = false
		script.Parent.Parent.DoorFrame.Script.Disabled = false
	end
end

I hope i can get some help there, i mostly dont script and learn from another scripts, thats why there may be a great amount of errors.

1 Like

door locking (since i can’t understand anything or whats happening in your script):

local locked = false

if locked then
   -- hey its locked
print('door is locked')
   -- return nothing since locked!
   return
else
  -- open the door? do animations or whatever
   print('door is un-locked')
  -- its un-locked
end

if you could show images or the error or whats happening, i am pretty sure people would be able to help you better.

1 Like

attempt to call a nil value means your trying to reference something that doesn’t exist. It would be helpful to have the line number of the error from the output to pinpoint the problem but usually it’s because of a spelling mistake or similar. Check your code at the line the output is referencing, it could be as simple as you forgot to capitalize the first letter of a variable.

1 Like

the open and the lock script are separate stuff
when its locked the script to open/close script is disabled and when its not locked its enabled

1 Like

can you show me the error if possible. it must show on what line the error is happening in Developer Console.

robloxapp-20210913-1737439.wmv (5.1 MB)
there, on the dev console it dont says any line

i changed a bit of the code and made the lock work, but now it dont unlocks anymore, i saw that i forgot the (function() on the proximityprompt.Triggered:Connect(), the error is also not there anymore

I would suggest adding debugs and instead of using separate script use the same script for each one.

just make it something like this:

local door = DOORPART -- this will be the door part which will get invisible or have animations when we open the door
local lock = LOCKVALUE -- a value to check if the door is actually locked or not
local lpp = LOCK_PROXIMITYPROMT -- your clicking or prompting value
local opp = OPEN_PROXIMITYPROMT -- your clicking or prompting value

opp.Triggered:Connect(function()
     if lock.Value then return end -- door is locked

      -- OPEN DOOR
end)

lpp.Triggered:Connect(function()
     if lock.Value then
           lock.Value = false -- unlocks the door
     else
           lock.Value = true -- locks the door
     end
end)

Just replace it with your animations and sounds, would be easy to manage and stuff.

The current script for opening/closing script is this one =

local frame = script.Parent
local Frame = game.Workspace.cooldor.DoorFrame
local openSound = frame:WaitForChild("DoorOpen")
local closeSound = frame:WaitForChild("DoorClose")
local proximityprompt = Frame:WaitForChild("ProximityPrompt")
local model = frame.Parent
local frameClose = model:WaitForChild("Door-Close")
local frameOpen = model:WaitForChild("Door-Open")
local opened = model:WaitForChild("Opened")
local tweenService = game:GetService("TweenService")

local debounce = true
proximityprompt.Triggered:Connect(function()
	if debounce == true then
		debounce = false
		if opened.Value == true then
			opened.Value = false

			closeSound:Play()
			tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameClose.CFrame}):Play()
		else
			opened.Value = true

			openSound:Play()
			tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameOpen.CFrame}):Play()
		end

		wait(.35)
		debounce = true
	end
end)

i kinda want to keep the current script due to having like 5 doors with this script in the game yet