Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
1
Answered by
chomboghai 2044 Moderation Voter Community Moderator
6 years ago

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.

0
Good response. Griffi0n 315 — 6y
0
I prefer game.Players:GetPlayerFromCharacter() because it makes sure it's a player and not an NPC Griffi0n 315 — 6y
0
Why would he use WhichIsA humanoid. He should be using OfClass humanoid. User#19524 175 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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)

0
Don't use deprecated methods Griffi0n 315 — 6y
0
Lmao on line 6 you’re overriding the k parameter. Plus keydown is deprecated. Go learn to use UIS or CAS User#19524 175 — 6y

Answer this question