Help Needed with E to interact

Okay, before I start, I want to make one thing clear…

UNLESS THERE ARE ABSOLUTELY NO AVALIABLE SOLUTIONS, I AM NOT GOING TO BE USING PROXIMITYPROMPTS.

Anyway…

I made this pretty simple e to interact door system that works for multiple models of doors, for easy access and as well for creations of different doors, if I need to do so later.

Anyway, I was coding along, and finished the code, but when I started to test it, somethings wouldn’t function properly

I’ll explain how it works roughly
The script detects when the player is hovering over a model, with a Value called “Tag” in it, if it has this tag, prompt up a billboard GUI, and let the player have the ability to press E, within around 10 studs, and it would open, simple right?

Anyway, some problems are:

1.) is that the first time I hover my mouse over a door, the GUI doesn’t appear until I press E, then it does

2.) Whenever I press e to a door, and leave it open, and then go to another, and press E, I would have to press two times, or even multiple times before anything happens.

Video:

These problems are really annoying, as it happens everytime, and have been looking for solutions for HOURS.

Here is where everything is by the way:

The Doors are located with a folder, for easy access, and they can work outside of the folder, if needed that is.

Screenshot 2022-09-05 010410

Then we have the tag editor plugin, making all the doors within a single tag, once again for easier use

This is the door model, Its main usage is the detector and the “Tag”, and the Hinge (everything is connected together using welds)

Screenshot 2022-09-05 010617

And then we have the script, and also the GUI (EToInteract) (pls ignore the other ones)

Screenshot 2022-09-05 010744

And then here is the code, there is only one code, and it is the ETIDOpener in the image above.

local CS = game:GetService("CollectionService")
local TS = game:GetService('TweenService')
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local player = game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local IsOpen = false
local Debounce1 = false
local Mouse = Player:GetMouse()

function DetectTag()
	UIS.InputChanged:Connect(function(input)
		if Mouse.Target then
			wait()
			if Mouse.Target:FindFirstChild('Tag') then
				Player.PlayerGui.ETointeract.Enabled = true
				Player.PlayerGui.ETointeract.Adornee = Mouse.Target
			else
				Player.PlayerGui.ETointeract.Enabled = false
				Player.PlayerGui.ETointeract.Adornee = nil
			end
		end
	end)
end

for _, EToInteractDoors in pairs(CS:GetTagged("EToInteractDoors")) do
	spawn(function()
		
		local doorOpen = TweenInfo.new(
			.75, -- time it takes
			Enum.EasingStyle.Quad, -- how it looks when it is easing
			Enum.EasingDirection.InOut, -- will it tween at the start and end, or only on one?
			0, -- repeat count
			false, -- will it reverse?
			0 -- delay time
		)
		local Hinge = EToInteractDoors.PrimaryPart

		local doorCframeOpen = TS:Create(Hinge, doorOpen, {
			CFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(125),0)
		})
		local doorCframeClose = TS:Create(Hinge, doorOpen, {
			CFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(0),0)
		})
			UIS.InputBegan:Connect(function(keycode)
				if Mouse.Target then
					if keycode.KeyCode == Enum.KeyCode.E then
						DetectTag()
							if Mouse.Target:FindFirstChild("Tag") then
								if(player.Position - Hinge.Position).magnitude <= 10 then
									if IsOpen == false and Debounce1 == false then
										Debounce1 = true
										doorCframeOpen:Play()
										IsOpen = true
										Debounce1 = false
									else
										Debounce1 = true
										doorCframeClose:Play()
										IsOpen = false
										Debounce1 = false
							end
						end
					end
				end
			end
		end)
	end)
end

Please, If you have any solutions, please respond, I would appreciate it!

Also, if you are going to present code, can you explain how it works? I’m still needing to learn a lot

2 Likes

What’s wrong with proximity prompts, You can customize them to look like anything you want and it doesn’t need to look like it’s default style

2 Likes

Yes, I am aware of that, but the proximityprompts don’t work like how I want them to, since the appear automatically near the player, instead of the player looking at the interactable object, and then appearing.

1 Like

First of all, this code will only work locally, so if you have other players they will be unable to see the door move. I personally would recommend adding a remote function or something to make sure it changes the door server side. (this is the reason you have to press it multiple times i think)

I think the problem is because your using InputChanged and because your input never changed that’s why its not getting updated

try this to see if it works

local runService = game:GetService("RunService")

runService.Heartbeat:Connect(function(deltaTime)
	if Mouse.Target == nil then return end
	if Mouse.Target:FindFirstChild('Tag') then
		Player.PlayerGui.ETointeract.Enabled = true
		Player.PlayerGui.ETointeract.Adornee = Mouse.Target
	else
		Player.PlayerGui.ETointeract.Enabled = false
		Player.PlayerGui.ETointeract.Adornee = nil
	end
end)
1 Like

I tried to change the InputChanged, and also use your code, but nothing worked.

I think the main problem is not with the adornee of the BillboardGui, but with the actual code of opening the door when the mouse is hovering over it, and then you can press e.

because you can still use the code even without the adornee to the door, so its most likely something with the actual pressing E of the door. (PS Im still trying to find a solution too)

Also, this game is only one player, so I don’t think it would matter if its on the server or not

it would seem better to use a custom proximity prompt. Their more efficient and can help out with the bugs you’re having along with others you may not have found yet.

1 Like