Guidance on Custom Proximity Prompt System

  1. What do you want to achieve? Keep it simple and clear!
    A gun system like the sample I have provided.

  2. What is the issue? Include screenshots / videos if possible!
    Would just like to create something like this:
    https://clearlydev.com/product/advanced-door-system-v1/

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I asked in a couple developer servers. I just need guidance. Trying to gain experience through the devforum as well. How can I create a proximity prompt system like the one I linked? The way it’s not 2d like a simple ScreenGui, and is dynamic and has a line from the player to it.

I am new to scripting, but not new to studio, been messing around in it for about 3 1/2 years now, but am just now starting to dip into scripting and modeling. Help and/or guidance would be appreciated it.

1 Like

Probably check whether the the distance between the player and the door is like maybe 5 studs (or whatever) away from the door. Then, just like draw the line from the Player’s HumanoidRootPart to the door.

You could do something like this (script in the door):

game.Players.PlayerAdded:Connect(function(Player)
  Player.CharacterAdded:Connect(function(Character)
while task.wait(1) do
if (script.Parent.Position - Character:WaitForChild(“HumanoidRootPart”).Position).Magnitude <= 5 then -- or whatever amount of studs
-- Draw the line and add your custom proximity prompt
game:GetService(“UserInputService”).InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
-- We’re using the “InputBegan” event in here because since it’s in here, they can only activate the proximity prompt in this function (if they press e and they aren’t close to a door it won’t do anything)
-- Your code
                 end
              end)
           end
        end
    end)
end)
2 Likes

I will try this out tomorrow as I am quite tired. (US time) - is it okay I reply with how it goes tomorrow or if I need more assistance?

1 Like

You can reply with the status whenever you do it (if it works or not idrk). It’s 5:47 PM (PST) for me.

1 Like

Alright, it is 7:47 PM for me. I appreciate the help very much and I hope I can get this work. I’m very happy to have just been accepted to the forum. I’m hoping this help me learn more. :blush:

1 Like

How could I draw the line, and would I need to use a surfaceGui for the prompt?

You could raycast from the HumanoidRootPart’s position to the door’s center point (then set a cylinder/ part to the raycast’s “position” to emulate a line). And you probably would need a surface / billboard gui.

Alright, working on adding the raycast now. I will let you know here in a bit.

Do you have any idea what is causing the underlines/errors?


https://gyazo.com/ba99482e1fe79111da30dbc5258d2378

I think I might need to add a few variables but I am not sure what.

i fixed the errors, and added so that when the players position is within the 5 studs you put it makes it visible, but now it doesnt work and outputs

Position is not a valid member of Workspace.Door

local promptFrame = script.Parent.BillboardGui.Frame

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		while task.wait(1) do
			if (script.Parent.Position - Character:WaitForChild("HumanoidRootPart").Position).Magnitude <= 5 then -- or whatever amount of studs
				promptFrame.Visible = true
				game:GetService("UserInputService").InputBegan:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.E then
						
					end
				end)
			end
		end
	end)
end)
1 Like

Is the door a model or a part? If it’s a model, you’ll have to use one of the parts in the model’s position instead.

Sorry for the late response btw

1 Like

No problem, it’s a model. I apologize, I am new to scripting. Maybe I should try and learn more before trying this. But I thought I was good enough to try and get experience making something for once.

Oh and by the way, you have to define “a” after the CharacterAdded event. If you don’t define it after, it doesn’t work. I won’t explain it but there’s a lot of good tutorials and explanations on that you could probably find.

1 Like

It’s okay, we all start somewhere. Just choose a part ig.

1 Like

Yeah, I removed that and will define it after that, where you mentioned to put the RayCast.

1 Like

I choosed a part and I get this error.

local promptFrame = script.Parent.BillboardGui.Frame

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		while task.wait(1) do
			if (script.Parent.Target - Character:WaitForChild("HumanoidRootPart").Position).Magnitude <= 5 then -- or whatever amount of studs
				promptFrame.Visible = true
				game:GetService("UserInputService").InputBegan:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.E then
						
					end
				end)
			end
		end
	end)
end)

I’m sorry, that was my mistake, I meant to put:


if (script.Parent.Target.Position - Character:WaitForChild("HumanoidRootPart").Position).Magnitude <= 5 then

Yeah, just replace that and I think it should work :slight_smile: (I just forgot to add the “.Position” at the end of script.Parent.Target).

local promptFrame = script.Parent.BillboardGui.Frame

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		while task.wait(1) do
			if (script.Parent.Target.Position - Character:WaitForChild("HumanoidRootPart").Position).Magnitude <= 5 then
				promptFrame.Visible = true
				game:GetService("UserInputService").InputBegan:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.E then
						
					end
				end)
			end
		end
	end)
end)

Hello, sorry for my absence. I noticed that it doesn’t work at first, but after I press E it is visible, but the magnitude has no play in the outcome. I am unsure why. I am literally stuck.

Maybe try replacing the above with this:

local Raycast = workspace:Raycast(Character.HumanoidRootPart.Position, Character.HumanoidRootPart.CFrame.LookVector)
if Raycast and Raycast.Instance.Name == script.Parent.Target.Name then

Still dunno if this will solve it (because the code that you already have written should’ve worked), but I guess you could give this a shot.

1 Like