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)
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!