Help Needed: Door Script Won't Budge Even with the Right Key!

Hey folks,

I’m wrestling with a script issue and could really use some insight. The idea is pretty straightforward: I’ve got a key, and when I hit the button to open the door, it should swing open. However, for some reason, it’s acting like I’m trying to pull on a push door – nothing! No action, no error in the output, and the print statement that should tell me I can’t open the door is nowhere to be seen.

Here’s the code snippet I’m working with:

local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer

local door = workspace.Model.Door
local hinge = workspace.Model.Hinge
local prompt = door.ProximityPrompt

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 requiredItemName = "Key"

prompt.Triggered:Connect(function()
	local backpack = player.Backpack
	local character = player.Character or player.CharacterAdded:Wait()
	local inventory = character:WaitForChild("Inventory")

	local hasKey = false
	for _, item in pairs(inventory:GetChildren()) do
		if item.Name == requiredItemName then
			hasKey = true
			break
		end
	end

	if hasKey then
		if prompt.ActionText == "Close" then
			tweenClose:Play()
			prompt.ActionText = "Open"
		else
			tweenOpen:Play()
			prompt.ActionText = "Close"
		end
	else
		print("You can't open this door.")
	end
end)

image

image

I’ve gone cross-eyed staring at this, but I can’t figure out what’s wrong. If anyone’s got a hunch or a clue, I’m all ears!

It’s driving me nuts because there’s no error showing up in the output, which makes it a real head-scratcher. Any suggestions or advice would be greatly appreciated!

Thanks a bunch for taking the time to help out!

1 Like

Hey, use prints to find out what line isn’t working correctly. I’m assuming its in the loop.

How can I do this? Where I put the prints?

Are you sure the player have “Key” in the player’s “Inventory” (I thinks it’s Folder in char) when you were testing?

Or maybe one of the parts of your door is anchored

1 Like

Put prints after each “if” and “else” statements.

I did this and nothing happens in output

Can you toggle comment on the Break and try again?

are you sure your inventory system stores your key under inventory and not backpack if its a tool that equips remember that roblox automatically puts it under character upon equipped and backpack when unequipped

1 Like

Sorry… If it didn’t print anything after that if then that wouldn’t matter. Can you add the print to the beginning to the promt function.