How would I detect what my cursor is pointing at?

I wanted to make a TextBox inside a gui, its text would be the part’s name (the part which the cursor points at). Do you have any idea how to make that kind of stuff?

local TextBox = script.Parent
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

Mouse.Move:Connect(function()
	if Mouse.Target then
		TextBox.Text = Mouse.Target.Name
	end
end)
4 Likes