Hey all!
I learned the mouse.Hit.p function a short time ago, and I need a little help with using it, how should I detect firstly, if it’s within a specfic range of the player, and secondly, if there’s another player on the location of the mouse?
Mouse.Hit.Position is the same as Mouse.Hit.p, I think the second is deprecated. It’s a position of a CFrame since Mouse.Hit is a CFrame. You would subtract the position between the mouse and the player and use Magnitude. Magntiude get’s the length of a vector as stated in the Developer Hub.
local Dist = (MousePos - PLAYER_HUMANOIDROOTPART_POSITION).Magnitude
The above line will subtract the 2 positions and get the magnitude of it. Magnitude won’t get the length of anything except a vector quantity, position is a vector quantity.
That could be done with @FerbZides solution above in the thread, but just saying if you have NPCs in your game too, you should check if the Target is actually a player and not a npc as both of them consist of a Humanoid.
local mouse = game.Players.LocalPlayer:GetMouse()
local Dist = (mouse.hit.p - [location of HRP]).Magnitude
local maxdist = [maxdistance]
if Dist < maxdist then
if mouse.Target:FindFirstChildOfClass("Humanoid") then
--effect
end
end
(Plr humanoidrootpart position - mouse position ).Magnitude < 10
– script here
and to get the target its mouse.Target , since u want to get plr >
if game.Players:GetPlayerFromCharacter(Mouse.Target.Parent) then
– its a player
end
// Sorry that I won’t write it in a script atm.
Since u want it to be like to connect if other mouse was there too u should create a instance.new part
at mouse position and if it gets pressed it shows who the part was from.