How do I check if the cursor is pointing at another player?

So I have a script where I get the cursor position. But here’s the question, how do I know if the player is pointing the cursor at another player? If he did, then print something

local Player = game:GetService('Players').LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Move:Connect(function()
	print(Mouse.X)
	print(Mouse.Y)
end)
1 Like

use Mouse.target it returns the part the player is pointing on, then check if its a player

Can you give me an example of exactly how to do this? Please

this would work

local Player = game:GetService('Players').LocalPlayer
local Mouse = Player:GetMouse()


Mouse.Move:Connect(function()
	local target = Mouse.Target
	if (not target) then return end
	
	local plr = game:GetService('Players'):GetPlayerFromCharacter(target.Parent)
	if plr then
		print(plr.Name)
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.