When using the mouse and pointing at the npc, his name appears

Hi, I’m again having a question that I can’t find the answer anywhere.
Therefore, the problem is this: I am creating a mechanism that, when the user points the mouse over the npc at a close distance, the name of that npc appears. The problem is that I didn’t find any way to do this, I know how to make the script detect the right name of the npcs but indicate the name of the npc when I point to it I don’t know. I think this is related to the GetMouse () instance, but I’m not sure.
Warning: I’m not asking someone to write the script but just to give an idea of how to do it.

When you get a player’s mouse, use its Target to determine whether a player is hovering over BaseParts. Then look for a unique characteristic of your NPCs (eg if its parent contains an Humanoid object) and check it in the script. Then get the NPC model’s Name and show it in a gui or locally set its humanoid display distance until his mouse is not hovering over it.

2 Likes

But you need mobile

Do this with UserInputService

then

Make a gui with the clicked players name

for example

if u clicked something that is

nil

then
output

print("Nil object no name")

or just describe your mouse vector
then get the player by the normal way

but check the humanoid and the targets name

then

just make the gui visible with the targets name that u got

edit: if u want distance i recommend doing

if rangeofMouse.Magnitude <= clickedPlayers.Magnitude then
           warn("Not close")
else
           script.Parent.TextGui.Text = targettedPlayer.Name
end)
1 Like