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.
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)
And then we have the script, and also the GUI (EToInteract) (pls ignore the other ones)
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