I've looked through many pages and i couldn't find the answer. I've seen many people suggesting the use of Magnitude but i don't understand how that would work because magnitude only represents the distance between two points in a straight line so if i want to create a circular area then i don't see how that could work out. I'm trying to make it so that within that area, all humanoids that are inside it will take damage so using the touched event won't work.
I don't see why a .touched event won't work? and you can aswell use magnitude for this, it will be harder. Since a touched event is easy to figure out by yourself, i'll be explaining you how to use magnitude for this.
magnitude
is a distance between 2 points, those 2 points are our 2 parts in studio, in normal maths the magnitude or distance between two points is the root of (vec.x + vec.y + vec.z)
so in lua you gotta do
local part1 = workspace.Part1 --or where ever your part is local part2 = workspace.Part2 --or where ever your part is local distance = (part1.Position - part2.Position).magnitude
there we go, thats pretty much how we use magnitude
now, if you wanna use this for your area checking, we pretty much have to choose our 1st part (it can be anything but i guess humanoidrootpart will be our best bet) and our 2nd part, and that can be an invisible and non concolided part, its just there to act up like a 2nd part so we have a distance to check. now, after we our first magnitude, we gotta find the distance that our 1st part has cant pass, or it will be damaged. for that we can just calculate that distance, by making another part near the edge of circle/sphere. and just a remeinde to get this magnitude you gotta
local part1 = workspace.Part1 local part2 = workspace.Part2 print((part1.Position - part2.Position).magnitude)
and now we got our distance in the output! now you can just remove this part and the script for it since its just for testing, and now we compare our 2 distances that we got!
and that should be it, this is how youre script is probarly going to look like, (this is a local script btw)
local plr = game:GetService("Players").LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() local part1 = char:WaitForChild("HumanoidRootPart", 0.1) local part2 = workspace.Part2 -- or where ever your second part is local dist = (part1.Position - part2.Position).magnitude local maxdist = 10.1245235112 -- this is the distance that we calculated and the distance we dont want humanoid to pass if dist <= maxdist then print("Humanoid is terrapassing!!") end
and that should be it, this isnt an efficent way, but my purpose is just to explain how this works!