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

How to find the distance of a Mouse Click?

Asked by 6 years ago

I read this and it worked (Goulstem's Answer) https://scriptinghelpers.org/questions/17049/how-would-i-fix-click-detectors-if-filtering-is-enabled

However, this makes it so you can click at any distance. I was wondering how you would make it so once it was clicked in the distance 10, then the script would carry out its function instead of anywhere > 10

This is the script

local Plr = game.Players.LocalPlayer
local mouse = Plr:GetMouse()
local part = workspace.Note

mouse.Button1Down:connect(function()
local Que = script.Parent.Parent.Parent.Quest
local targ = mouse.Target
if targ == part then

No errors, just simply want to know if anyone else knows how to make it so this only functions from the distance less or equal to 10 ...thanks

1 answer

Log in to vote
0
Answered by 6 years ago

Basically, you have to get player's position and distance between him and target. So first, take player's position (in this case i will take the position of player's head):

local pos = Plr.Character.Torso.Position

then take the distance between head and target and make the 'if' statement:

if (pos - targ.Position).magnitude <= 10 then
0
or you can do Plr:DistanceFromCharacter(vector3 value) F4ULT1NTH3D4T4 226 — 6y
Ad

Answer this question