✓ Accepted answer
When you hover over another player's character, Mouse.Target is the part inside of their character that your mouse is hovering over, not the entire character model.
To get the character model, just do this:
local Player = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
If your mouse is hovering over someone's character, it should work and say that you're hovering over a player's character.
Also, two things.
script.Parent.Equipped:connect(function(Mouse)
local Player = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
if Mouse.Target ~= nil and Player then
print(Mouse.Target.Name)
end
end)
I wouldn't check to see if Mouse.Target is nil after I use it as an argument in a function.
:connect is deprecated, meaning it has a newer version and it may not work properly in the future; use :Connect instead. It's just unsafe to use deprecated functions.
Here's the full version of the fixed code:
script.Parent.Equipped:Connect(function(Mouse)
if Mouse.Target ~= nil then
local Player = game.Players:GetPlayerFromCharacter(Mouse.Target.Parent)
if Player then
print(Mouse.Target.Name)
end
end
end)
1 comment
TargetFilter perhaps?