You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to see if a player pressed E next to a specific part.
What is the issue? Include screenshots / videos if possible!
I don’t know how to check if a player pressed E next to a specific part.
And I don’t have any screenshots and videos.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking in Developer Forum but I couldn’t find the right topic that I need to solve this.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
You could use a Proximity Prompt for this, but, if you don’t want to, you could check the distance after they press it:
local uis = game:GetService("UserInputService")
local part = --define the part
local plr = game.Players.LocalPlayer
uis.InputBegan:Connect(function(input, typing)
if not typing then
if input.KeyCode == Enum.KeyCode.E then
if plr.Character then
if (plr.Character.HumanoidRootPart.CFrame - part.CFrame).Magnitude < 2 then
print("Close enough.")
end
end
end
end
end)
local Part = game.Workspace:WaitForChild("TestPart")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local char = Player.Character
UIS.InputBegan:Connect(function(code)
if code.KeyCode == Enum.KeyCode.E then
if (char.HumanoidRootPart.Position - Part.Position).Magnitude < 15 then
print(Player.Name.."pressed E next to a part!")
end
end
end)