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

[Solved] distance between player and mouse target?

Asked by 6 years ago
Edited 6 years ago

I solved this issue after many hours of experimenting with magnitude; thanks to any who responded.

To make a gui visible from a certain distance, I have this working script:

player = game:GetService("Players").LocalPlayer
mouse = player:GetMouse()
rs = game:GetService("RunService").RenderStepped
gui = script.Parent

rs:connect(function()
    if mouse.Target then
        local pos1 = mouse.Target.Position
        local pos2 = player.Character.Torso.Position
        local magnitude = (pos1 - pos2).magnitude
        if magnitude <=33 and mouse.Target and mouse.Target:FindFirstChild("Interact")then
        gui.Visible = true
        gui.Text = mouse.Target.TextValue.Value
        gui.Position = UDim2.new(0,mouse.X+15,0,mouse.Y+15)
    else
        gui.Visible = false
    end
end
        end)
1
can't u just use a regular click detector? greatneil80 2647 — 6y
0
If you never knew, CLICK DETECTORS ARE NOT FOR GUIS hiimgoodpack 2009 — 6y
0
What problems did you have when you used magnitude? PreciseLogic 271 — 6y

Answer this question