Get what section of the part the player is in?

st

Here is a visual representation of what I mean. The square is the part and black grid is the different sections. They’re uneven in the drawing, that isn’t intentional.

I’m trying to get the section of the part the player is in, but I don’t even know where to start. Any help is appreciated and let me know if I could provide any additional information!

(Not asking someone to write an entire script, just looking for guidance on where to start)

1 Like

Put different parts in each section. Use the touched event to tell where the player is.

1 Like

I’m checking this every heartbeat (for my anticheat to not miss any frames) and I don’t think this is the most reliable or performant solution. I should’ve included that in my original post, apologies!

For more context, I have the part.Position as a variable and the humanoidrootpart.Position as a variable.

No idea how you would do this, but you could get the position of the corners of the part. Then you could divide the x and y by 3 to get the corners of the sections.

1 Like

It would be better to use BasePart:GetTouchingParts() instead of the BasePart.Touched event. Whenever you need to see which part the player is in, just use an in pairs() loop to check all the parts, then see if any of those parts are touching a player’s character.

1 Like

You can use Region3.new to get this job done.
If you had a model/folder with parts in it, you could do model/folder:GetChildren() and add them to a table.
Then loop through the table parts in a function with a region3 check and returns the part which the player is currently in

1 Like

I’m trying to use math instead of Region3 or anything like it. Thank you though.

No worries, I changed up my region3 script to work with just calculations, in math terms

local Parts = {}

for i,v in next, workspace:WaitForChild("Folder"):GetChildren() do --Edit the workspace path here
	if v:IsA("BasePart") then
		table.insert(Parts,v)
	end
end

local function check()
	for i,v in next, Parts do
		for _,plr in pairs(game:GetService("Players"):GetPlayers()) do
			local Root = plr.Character:WaitForChild("HumanoidRootPart")
			local Exterior = Vector3.new(v.Size.X/2,Root.Position.Y,v.Size.Z/2)
			local Position = v.Position + Exterior
			local Magnitude = (Root.Position - Position).Magnitude
			if (Root.Position - Position).Magnitude <= Exterior.Magnitude then
				return plr -- When this finds a player, it like cancels the function sorta and only returns this. No need to worry about extra players
			end
		end
	end

	return nil
end

while wait() do
	local FoundPlayer = check()
	if FoundPlayer ~= nil then
		warn(FoundPlayer) -- Do whatever you want in this IF statement
	end
end
1 Like

If you need more things that you need help with, Kyurem102#8082 is my tag. (Discord

1 Like
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")

local part = workspace:WaitForChild("Part")

while task.wait(2) do
	if hrp.Position.X >= part.Position.X - part.Size.X/2 and hrp.Position.X <= part.Position.X + part.Size.X/2 and
		hrp.Position.Y >= part.Position.Y - part.Size.Y/2 and hrp.Position.Y <= part.Position.Y + part.Size.Y/2 and
		hrp.Position.Z >= part.Position.Z - part.Size.Z/2 and hrp.Position.Z <= part.Position.Z + part.Size.Z/2 then
		
		if hrp.Position.Z <= part.Position.Z - part.Size.Z/3 then
			if hrp.Position.X <= part.Position.X - part.Size.X/3 then
				print("Player is in segment one.")
			elseif hrp.Position.X >= part.Position.X + part.Size.X/3 then
				print("Player is in segment three.")
			else
				print("Player is in segment two.")
			end
		elseif hrp.Position.Z >= part.Position.Z + part.Size.Z/3 then
			if hrp.Position.X <= part.Position.X - part.Size.X/3 then
				print("Player is in segment seven.")
			elseif hrp.Position.X >= part.Position.X + part.Size.X/3 then
				print("Player is in segment nine.")
			else
				print("Player is in segment eight.")
			end
		else
			if hrp.Position.X <= part.Position.X - part.Size.X/3 then
				print("Player is in segment four.")
			elseif hrp.Position.X >= part.Position.X + part.Size.X/3 then
				print("Player is in segment six.")
			else
				print("Player is in segment five.")
			end
		end
	end
end

Decided to create a solution for this which is solely math based, worked when testing.

1 Like