How to make click to interact object without directly looking it?

I have proximity prompt for doors using the E button, but i also want another way to open it, that is by clicking near the proximity prompt when it’s visible without directly looking at the prompt, It’s like the interaction system in SCP: Containment Breach for when you have to stare at SCP-173 but also get out of it’s sight.

Here’s the Proximity Prompt code

Prox.Triggered:Connect(function(player)
	if Prox.HoldDuration and Prox.HoldDuration == 0 then
		print("work")
		if debounce then return end
		debounce = true
		if open == false then
			tween()
			open = true
			script.Parent.soundthing.dooropen:Play()
			if script.Parent.soundthing.dooropen:Play() then
				script.Parent.soundthing.dooropen:Destroy()
			end
		else
			tweenr()
			open = false
			script.Parent.soundthing.doorclose:Play()
			if script.Parent.soundthing.doorclose:Play() then
				script.Parent.soundthing.doorclose:Destroy()
			end
		end
		task.wait(1.5)
		debounce = false
	end
end)

Hello! I tried to help you solve this issue. I hope it helps. If I did not solve this issue - tell me, I will try to solve it again.

In properties of your door part you should add an Attribute (scroll down), click “+” and then add the attribute with Name “ClassType”, type “string” and then give it a value: Door

Add the RemoteEvent in your door part and name it “Interact”.

LocalScript (put in starterplayerscripts):

local uis = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer

local prompt

plr:GetMouse().Button1Up:Connect(function()
	for i, v in workspace:GetDescendants() do
		if plr.Character == nil then return end
		local hrp = plr.Character:FindFirstChild('HumanoidRootPart')
		if hrp == nil then return end -- stops working when no character
		if v:FindFirstChildOfClass('ProximityPrompt') then prompt = v:FindFirstChildOfClass('ProximityPrompt') end
		if v:GetAttribute('ClassType') and v:GetAttribute('ClassType') == 'Door' and (v.Position - hrp.Position).Magnitude <= prompt.MaxActivationDistance then
			v.Interact:FireServer()
			break -- to prevent interacting with more than one door
		end
	end
end)

Edit your door script. Add these lines:

yourDoorPartHere.Interact.OnServerEvent:Connect(function()
	print("work")
	if debounce then return end
	debounce = true
	if open == false then
		tween()
		open = true
		script.Parent.soundthing.dooropen:Play()
		if script.Parent.soundthing.dooropen:Play() then
			script.Parent.soundthing.dooropen:Destroy()
		end
	else
		tweenr()
		open = false
		script.Parent.soundthing.doorclose:Play()
		if script.Parent.soundthing.doorclose:Play() then
			script.Parent.soundthing.doorclose:Destroy()
		end
	end
	task.wait(1.5)
	debounce = false
end)

IMPORTANT!
Type in your door part name where “yourDoorPartHere” is in script.

And why don’t you just create a function in your script to make it more convenient and flexible?

1 Like

I got somewhere with that code, however it broke once i opened the door, said that position is not a valid member of camera “workspace.camera”. I am scripting the buttons to the doors, since the doors already have their animations for opening and closing (tween and tweenr).

I also already have a custom proximity prompt code (also in starterplayerscripts), which might be able to support the feature i want

local ProximityPromptService = game:GetService("ProximityPromptService")

ProximityPromptService.PromptShown:Connect(function(promptInstance: ProximityPrompt)
	if promptInstance.Style == Enum.ProximityPromptStyle.Default then return end
	local CustomProximity = game.ReplicatedStorage:WaitForChild("CustomProximity"):Clone()
	CustomProximity.Parent = promptInstance.Parent
	promptInstance.PromptHidden:Once(function()
		if CustomProximity then
			CustomProximity:Destroy()
		end
	end)
end)

to answer your about function, ̶i̶ ̶p̶r̶o̶b̶a̶b̶l̶y̶ ̶s̶h̶o̶u̶l̶d̶ ̶d̶o̶ ̶t̶h̶a̶t̶ ̶b̶u̶t̶ ̶i̶ ̶d̶o̶n̶’̶t̶ ̶k̶n̶o̶w̶ ̶h̶o̶w̶ figured it out

Nevermind got it, just had to put the attributes in the buttons since the doors (2 sliding doors) already have their tween animations. Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.