I am trying to get the players near the player mouse programtically? I have no idea how I would do that.
1 Like
This question is not clear, but if what you really say is like being in the first person, just use the mouse wheel forward and that’s it, or else Pressing “I”.
I edited my post to clarify.
tirty char
What are you trying to make? Here’s some articles, you can use Mouse.Hit
to get the mouse’s CFrame.
local Mouse = game.Players.LocalPlayer:GetMouse()
local Camera = workspace.CurrentCamera
local function GetClosestPlayer()
local Closest = {nil, nil}
local MousePos = Vector2.new(Mouse.X, Mouse.Y)
for _, Player in pairs(game.Players:GetPlayers()) do
if Player == game.Players.LocalPlayer then continue end
local Character = Player.Character
if Character then
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
local vector, onScreen = Camera:WorldToScreenPoint(HumanoidRootPart.Position)
if onScreen then
local Distance = (MousePos - Vector2.new(vector.X, vector.Y)).Magnitude
if Closest[1] == nil then Closest = {Distance, Player} continue end
if Distance < Closest[1] then
Closest = {Distance, Player}
end
end
end
end
end
return Closest
end
Something like this?
4 Likes