Detecting if player is inside a room

im trying to make system that will generate a area inside a room

example:
image

the grey stuff are walls

and the brown thing is the area that the script should generate

all i thought about are raycast but i have no idea how to put it together

while not the best option, the Touched event might be a solution.

This is a script from a really old project where I used “zones”, which were basically big parts, to display a message (Think of it as when you enter a city and it’s name is displayed briefly on your screen)

local Players = game:GetService("Players")
local Run = game:GetService("RunService")
local TweenService = game:GetService('TweenService')
local Zone = script.Parent

local PlayersWithGui = {}

Run.Heartbeat:Connect(function()
	for _, Player in ipairs(Players:GetPlayers()) do
		if Player then
			local PlayerGui = Player:WaitForChild("PlayerGui")
			local PlrGui = PlayerGui:WaitForChild("Zone")
			local ZoneUI = PlrGui:WaitForChild("Zone1")
			local Text = ZoneUI:WaitForChild("Zone1Text")
			local Character = Player.Character
			local tween = TweenService:Create(
				ZoneUI,
				TweenInfo.new(3), -- Amount of seconds
				{BackgroundTransparency = 1} -- Goal
			)
			local texttween = TweenService:Create(
				Text,
				TweenInfo.new(3), -- Amount of seconds
				{TextTransparency = 1,
				TextStrokeTransparency = 1} -- Goal
			)
			if Character then
				local HRP = Character:WaitForChild("HumanoidRootPart")
				if HRP.Position.X >= Zone.Position.X - Zone.Size.X/2 and HRP.Position.X <= Zone.Position.X + Zone.Size.X/2 and
					HRP.Position.Y >= Zone.Position.Y - Zone.Size.Y/2 and HRP.Position.Y <= Zone.Position.Y + Zone.Size.Y/2 and
					HRP.Position.Z >= Zone.Position.Z - Zone.Size.Z/2 and HRP.Position.Z <= Zone.Position.Z + Zone.Size.Z/2 then
					local TablePlayer = table.find(PlayersWithGui, Player)
					if not TablePlayer then
						table.insert(PlayersWithGui, Player)
						if not ZoneUI.Visible then
							ZoneUI.BackgroundTransparency = 0
							Text.TextTransparency = 0
							Text.TextStrokeTransparency = 0
							ZoneUI.Visible = true
							tween:Play()
							texttween:Play()
							task.delay(2, function()
								ZoneUI.Visible = false
							end)
						end
					end
				else
					local TablePlayer = table.find(PlayersWithGui, Player)
					if TablePlayer then
						table.remove(PlayersWithGui, TablePlayer)
						if ZoneUI.Visible then
							ZoneUI.Visible = false
						end
					end
				end
			end
		end
	end
end)

if you want to do that, you can do:

local Players = game:GetService("Players")
local Run = game:GetService("RunService")
local Zone = script.Parent

local insidePlayers = {}

Run.Heartbeat:Connect(function()
	for _, Player in ipairs(Players:GetPlayers()) do
		if Player then
			local Character = Player.Character
			if Character then
				local HRP = Character:WaitForChild("HumanoidRootPart")
				if HRP.Position.X >= Zone.Position.X - Zone.Size.X/2 and HRP.Position.X <= Zone.Position.X + Zone.Size.X/2 and
					HRP.Position.Y >= Zone.Position.Y - Zone.Size.Y/2 and HRP.Position.Y <= Zone.Position.Y + Zone.Size.Y/2 and
					HRP.Position.Z >= Zone.Position.Z - Zone.Size.Z/2 and HRP.Position.Z <= Zone.Position.Z + Zone.Size.Z/2 then
					local TablePlayer = table.find(insidePlayers, Player)
					if not TablePlayer then
						table.insert(insidePlayers, Player)
						-- if player enters area
					end
				else
					local TablePlayer = table.find(insidePlayers, Player)
					if TablePlayer then
						table.remove(insidePlayers, TablePlayer)
						-- if player leaves(??)
					end
				end
			end
		end
	end
end)

again, this is pretty old and you may need to tweak it a little, but when I had this script it worked!

oh i think you misunderstood the post, i need a script that will detect if play is inside a room because i could do zones as big parts but play have the ability to build on his own plot so i need the script to detect if player is indoor and create indoor zone