Creating a paremeters system to check if a character is in a certain area [SOLVED]

Hi all, trying to create a parameters system - but to no avail. I’ve tried searching youtube, google, the DevForum (found some posts similar- none answering my questions though) and asking around on chats… no help recieved. The way this system is supposed to work is that there are 6 parts, (2 parts for each axis), the point of this is to check if a character is situated in a certain area. This is my first time attempting some sort of system like this, the code below is how I imagined it to be;

function getParams(char,x,x2,z,z2,y,y2)
	local humRoot = char:FindFirstChild("HumanoidRootPart")
	local humPos = humRoot.Position
	if humPos.Z > z2 and humPos.Z < z and humPos.Y > y and humPos.Y < y2 and humPos.X > x and humPos.X < x2 then
		print("returned true")
		return true	

local Params = currentFloo.Parameters -- this is the model which contains the 6 parts
if getParams(FlooPlr.Character,Params.x.Position.X, Params.x2.Position.X, Params.z.Position.Z, Params.z2.Position.Z, Params.y.Position.Y, Params.y2.Position.Y) == true then
   -- puts what i want the script to do here

This is what the 6 parts location looks like;

The issue is that nothing seems to be happening. No printing, etc… I’m unsure what the issue is because this is my first time making a system like this but any feedback would be welcomed!

I await your responses, any help/feedback is appreciated - posts, videos etc. :slightly_smiling_face:

there is already something similar, you can probably just do this

local function getParams(char,Cframe,RegionSize)
   return table.find(workspace:GetPartsBoundInBox(Cframe,RegionSize),char.PrimaryPart) and true or false

I did not know this existed, I will try this- thanks! :smiley:

Hi! Thank you for showing me this, this helped me alot and pushed me in the right direction… however this function did not work for whatever reason… I decided to use a variant of this function… workspace:GetPartsInPart()

My code looked something a bit like this…

 function getParams(char,parameterpart)
	if table.find(workspace:GetPartsInPart(parameterpart),char.PrimaryPart) then
		print(Char.Name.." found in "..parameterpart.Name)
		return true

if getParams(character,part) == true then
    -- does what i want the script to do here

Thank you alot for your help! :smiley:

1 Like