Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Measuring Range in Roblox? No result online! Need help!

I'm trying to measure a range for NPC's like any other game than the NPC Will fight/chase after the other NPC or player. But first, I have to learn how to measure range in ROBLOX.

Now I know 1 kind of range is Studs but I have no idea on that because this may be the first time working with that.

That other thing I could do is create a circular part under the NPC and when someone touches the circular party the NPC will chase after them.

Now that IS a way to do it but there must be a more efficient and easier way to do it or else I would have to spam those all over the place and the game eventually lag.

Any feed back, help support is appreciated. Thank you.

I will also accept links to explanations as feedback and support.

Sorry, this sounds like a script request but I had no results through online searches and videos nor the Roblox Wiki.

2 answers

✓ Accepted answer

You need to use magnitude to accomplish that. Heres an example:

local camera = game.Workspace.CurrentCamera
local part = workspace.SomePart --Locate your part here
local studsAway = 18 --set how many studs you the player needs to be in range of
game:GetService("RunService").RenderStepped:connect(function()
    if (camera.CoordinateFrame.p - part.Position).magnitude < studsAway then 
--do something
print("hey")
    end
end)

I'm pretty sure this needs to be in a LocalScript though. Please accept answer if this helped though!

4 comments

0

But i need to do something like if someone is in a certain range of studs then activate my code. How?

0

I got it.

0

Just updated my question for you.

0

Thanks

Use RayCasting

2 comments

0

Thats gonna take a lotta rays to go a whole 360 around the character.

0

No. not really.

This discussion is preserved as it was. New answers, comments, and votes are closed.