Tool in hand not detecting part OnTouch

Hello,

So basically I’m currently working on a little puzzle in which a picklock is required to open a door. The way it works is that you touch the door’s hitbox part with the tool in your hand in which afterwards enables the script for the door that lets you open and close it. The problem I’m currently facing is that for some reason the tool isn’t detecting the part? Here’s the setup + 2 simple scripts:

Setup image #1:
image

Setup image #2:
image

Inside the “MetalDoorScript” script (Enables the disabled “DoorScript” script which makes the door functionable after touching “LockpickingHitbox” part with the tool in your hand):

local LockpickingHitbox = script.Parent
local LockpickProp = game.Workspace.Givers.lockpick
local LockpickingSound = LockpickingHitbox.LockpickingSound
local Proximity = LockpickingHitbox.Parent.DoorFrame.ProximityPrompt
local DoorScript = LockpickingHitbox.Parent.DoorScript

function ontouch(hit)
	local lockpickkey = hit:findFirstChild("lockpickkey")
	if lockpickkey then hit.Parent:Destroy()
		LockpickProp:Destroy()
		LockpickingSound:Play()
		script.Disabled = true
		LockpickingSound.Ended:Wait()
		script.Disabled = false
		DoorScript.Enabled = true
		Proximity.Enabled = true
		LockpickingHitbox:Destroy()
	end
end
script.Parent.Touched:Connect(ontouch)

The code inside “DoorScript” (Makes the door be able to open/close using a ProximityPrompt):

local frame = script.Parent:WaitForChild("DoorFrame")
local openSound = frame:WaitForChild("DoorOpen")
local creakSound = frame:WaitForChild("DoorCreak")
local closedSound = frame:WaitForChild("DoorClosed")
local proximityprompt = frame:WaitForChild("ProximityPrompt")
local model = script.Parent
local frameClose = model:WaitForChild("DoorFrameClose")
local frameOpen = model:WaitForChild("DoorFrameOpen")
local tweenService = game:GetService("TweenService")

proximityprompt.Triggered:Connect(function()
	if 	proximityprompt.ActionText == "Close" then
		proximityprompt.ActionText = "Open"
		creakSound:Play()
		frame.CanCollide = true
		tweenService:Create(frame,TweenInfo.new(1.845),{CFrame = frameClose.CFrame}):Play()
		wait(1.74349)
		closedSound:Play()
		else
		proximityprompt.ActionText = "Close"
		openSound:Play()
		frame.CanCollide = false
		tweenService:Create(frame,TweenInfo.new(1.845),{CFrame = frameOpen.CFrame}):Play()
		end
	end)

Am I overlooking something? The weirdest part is that there’s no errors in the output and I’ve also made sure that the hitbox part has CanTouch enabled but it still seems to not detect the part. This OnTouch script has worked with some other similar puzzles with no problem, not sure what’s going on this time.

Image of the famous part:

It’s an invisible MeshPart the same size as the door and in the same position as it. I’d appreciate any of your help on this issue as this is frustrating now! Hope my explanation made sense.

1 Like

I’m not so good at scripting, but do you possibly have the CanTouch Property of the Part checked as false?

How are you setting proximityprompt.ActionText to “Close” at the beginning of the script? Are you doing it manually beforehand, or did you forget it in the beginning part of the second script?

1 Like

No, the script that makes the door work (“DoorScript”) has no problems, not worried about that one. The only script giving me trouble is the other one (“MetalDoorScript”) for said reason. There’s no errors in output relating to it yet isn’t working for some reason.

I’m not much of a scripter but I would do something like.

“MetalDoorScript”

Script.Parent.Touched:Connect(Function(hit)
if Hit:IsA(“Tool”) and Hit.Parent.Name = “lockpickkey” then
(Put the what you want to happen in here)
end)
end

If you need anymore help then tell me.

And if it doesn’t work tell me and I’ll try fix it.

I believe the issue is in the Metal Door Script line 8 hit:findFirstChild("lockpickkey") perhaps if you uppercase the the f in find it would work? also if FindFirstChild doesn’t find any child then it’ll simply return nil without erroring, that may be also why your output doesn’t have any errors in it

The hitbox part has CanTouch enabled, but I was asking about the Part that’s hitting the hitbox, not the hitbox itself.

Also, try:

proximityprompt.Triggered:Connect(function()
    print("Triggered ",proximityprompt.ActionText) 
	if 	proximityprompt.ActionText == "Close" then
		proximityprompt.ActionText = "Open"

which will tell you when proximityprompt gets triggered what the value of .ActionText is so you can see which of the if or else sections will be run.

I also just noticed that in the if... == "Close" section you are calling for the CFrame = frameClose tween. I don’t know if you have the tween for frameClose as the opening animation or the closing animation. Personally I would have made the opening tween named frameOpen, but you may have done it the other way.

As I was messing around with the LockpickingHitbox properties, I found out that the reason I was getting this OnTouch issue was due to said part not having a MeshID as it’s a MeshPart after all, thus causing it to be dead in a way and uninteractable. Easily fixed it by giving it a meshID lool. I appreciate everyone who tried helping!!

1 Like