Press key when looking at something to interact

This is essentialy what you want, put it in a local script in starter player scripts.

local uis = game:GetService("UserInputService")
local mouse = game.Players.LocalPlayer:GetMouse()

uis.InputBegan:Connect(function(input, gp)
	if gp then return end
	if input.KeyCode == Enum.KeyCode.E then
		if mouse.Target == [YOUR TARGET] then
			-- your code here
		end
	end
end)
1 Like