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

How I get the closest attachment to my mouse?

Asked by
Kblow1 53
4 years ago

Hello guys!

Im looking to figure out how i can get the closest "attachment" to my mouse, basically i have a ray that detects which part im looking at and i have a floor with 4 attachments i wanna get the closest attachment to my mouse. Here is my current code. Its not working!

local function GetAttachment(x,y)
    local nearestAttachment = nil
    local target = mouse.Target
    for i,v in pairs(hit:GetChildren()) do
        if v:IsA("Attachment") then
            local mag = (mouse.Hit.p - hit.Position).magnitude
            if mag < 2 then
                print(v.Name)
            end
        end
    end
end

Basically "hit" is the object the ray is touching! Thanks again!

0
Use game.RunService.RenderStepped():Connect() pranvexploder 14 — 4y
0
For what though? The function is already in a renderstep. Kblow1 53 — 4y

Answer this question