Door Interaction Issues

local interactModules = script:GetChildren()

for _,module in pairs(interactModules) do
	local information = require(module)
	for _,object in pairs(information.objects) do
		local newPrompt = Instance.new("ProximityPrompt")
			newPrompt.RequiresLineOfSight = false
			--newPrompt.Style = Enum.ProximityPromptStyle.Custom
			for property, value in pairs(information.prompt) do
				newPrompt[property] = value
			end
			newPrompt.Parent = object.PrimaryPart
		information.Setup(newPrompt)
	end 
end

local interactions = {}

function interactions.Enable(bool)
	for _, proximityPrompt in pairs(interactModules) do
		proximityPrompt.Enabled = bool
	end
end

return interactions

This code here works nicely shown is this video:

But it is not the result I’ve been trying so hard to get
I’ve tried making it myself and been trying to fix this for hours now so here I am

			local function GetDistance(p1,p2)
			    local Distance = (p1.Position - p2.Position).magnitude
			    return Distance
			end
		    local mouse = player:GetMouse()
		    if mouse.Target and mouse.Target.Name == "DoorPart" then
				if GetDistance(object.PrimaryPart, HumanoidRootPart) < 7.5 then  
					--print((object.PrimaryPart.Position - HumanoidRootPart.Position).magnitude, object.PrimaryPart.Name)
				    GameGUI.InteractionUI.Visible = true
					newPrompt.Enabled = true
					information.Setup(newPrompt)
				end
			else
		     	GameGUI.InteractionUI.Visible = false
				newPrompt.Enabled = false
		    end

That breaks everything, ill make some code to show in short what Im trying to do

if IsInRange and mouse.Target and mouse.Target.Name == "DoorPart" then
--Enable the prompt and my screengui
else
--Disable the prompt and my screengui
end

I have no idea how to accomplish this so any help on the issue would be appreciated!

1 Like

This doesn’t appear to be in a loop or anything, therefore it will run in the beginning, see that the mouse.Target in’t “DoorPart”, then it will never check again.

1 Like

Yes but I’m not really sure where to put it.

Well at the bottom you could have a while wait() loop, and detect if the mouse’s target is a door part. If it is a door part, then set a variable names “SafePart” to the model that the part is in. Then set the ProximityPrompt’s Enabled for that part to true. Then loop through all the scripts children, check if that child is the mouses target, if it isn’t then disable the proximity prompt for that object.

1 Like

I almost got it but now only one door activates.

local interactModules = script:GetChildren()

local player = game.Players.LocalPlayer
local HumanoidRootPart = player.Character.HumanoidRootPart
local PlayerGui = player:WaitForChild("PlayerGui")
local GameGUI = PlayerGui:WaitForChild("Interact")

for _,module in pairs(interactModules) do
local information = require(module)
	for _,object in pairs(information.objects) do
		newPrompt = Instance.new("ProximityPrompt")
			newPrompt.RequiresLineOfSight = false
			newPrompt.Enabled = false
				--newPrompt.Style = Enum.ProximityPromptStyle.Custom
				for property, value in pairs(information.prompt) do
				newPrompt[property] = value
			end
			obj = object.PrimaryPart
			newPrompt.Parent = object.PrimaryPart
		information.Setup(newPrompt)	
	end
end

local interactions = {}

function interactions.Enable(bool)
	for _, proximityPrompt in pairs(interactModules) do
		proximityPrompt.Enabled = bool
	end
end

local function GetDistance(p1,p2)
	local Distance = (p1.Position - p2.Position).magnitude
	return Distance
end

local mouse = player:GetMouse()
while wait() do
	if mouse.Target and mouse.Target.Name == "DoorPart" then
		if GetDistance(obj, HumanoidRootPart) < 7.5 then  
			--print((object.PrimaryPart.Position - HumanoidRootPart.Position).magnitude, object.PrimaryPart.Name)
			GameGUI.InteractionUI.Visible = true
			newPrompt.Enabled = true
		else
			GameGUI.InteractionUI.Visible = false
			newPrompt.Enabled = false
		end
	else
		GameGUI.InteractionUI.Visible = false
		newPrompt.Enabled = false
	end 
end

return interactions

I gtg, I can help you later. Good luck!

1 Like

Alright seeya later man, Thanks for the help too.

1 Like