Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Print a player's name that is indicated by mouse?

Alright, I wanted to print a player's name when I put my mouse on it's character, I tried to do the game.Players.LocalPlayer:GetMouse().Hit but it didn't work though. So I was wondering, if you could help me, thank you so much.

2 answers

✓ Accepted answer

use Target rather than Hit because the former gives the object, and the latter gives the position. You can use game.Players.LocalPlayer:GetMouse().Target.Parent and that should give you the character. Make sure to check it's a character though by doing :FindFirstChildWhichIsA("Humanoid") and checking to see if that exists.

3 comments

0

Good response.

0

I prefer game.Players:GetPlayerFromCharacter() because it makes sure it's a player and not an NPC

0

Why would he use WhichIsA humanoid. He should be using OfClass humanoid.

Already done. That's what I did:

local m = game.Players.LocalPlayer:GetMouse()
local ErasureActive = game.ReplicatedStorage.ErasureActive.Value
local ttime = "ok"

m.KeyDown:connect(function(k)
k = k:lower()
if k == 'z' then 
 if ttime == "ok" then
  local target = game.Players.LocalPlayer:GetMouse().Target
  local h = target.Parent:FindFirstChild('Humanoid')
  if h then
	print(h.Parent.Name)
end
end
end
end)

2 comments

0

Don't use deprecated methods

0

Lmao on line 6 you’re overriding the k parameter. Plus keydown is deprecated. Go learn to use UIS or CAS

This discussion is preserved as it was. New answers, comments, and votes are closed.