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

How to check if a player is in a certain room?

I've been wondering if there is a way to check through every player to see if they are standing inside a certain block. In this case the block would be filling the entire room, as that would check if they were in the room.

I'm able to cycle through a table containing each character, but I would like to know the event or function that can check if that character is touching the block, so that in turn I can check if they are in the room.

3 comments

0

You can use the Touched event or Region3 to check if their character is inside a certain area.

1

You can put two parts in opposite corners of the certain room and make an if statement where if the position of the player is between the X and Z values of the parts then do something. However, if there are multiple stories to the building with the specific room, include the Y value and make one part in the bottom vertex and another part in the opposing top vertex.

0

Thanks, haven't tried this yet but I'm sure it'll work.

1 answer

I know this way may be unpractical, but its the only way i see it could work using my lua knowlegde. Basicly, put an IntValue called Room in the StarterPlayer folder. Then put a localscript inside the StarterPlayer folder too.

Then use the Touched event inside an invisible part with no collision that you can put at the entrances of every room. Here's what to put in the local script.

local Bathroom = game.workspace.part --Change part with the name of the part to put in the entrance of the room.

local function BathroomEnter()
    script.parent.Room = Bathroom
end

Bathroom.Touched:connect(BathroomEnter)

You can easily code a room with two or more entrances like so:

local Kitchen1 = game.workspace.part --Change part with the name of the part to put in the entrance of the room.
local Kitchen2 = game.workspace.part

local function KitchenEnter()
    script.parent.Room = Kitchen
end

Kitchen1.Touched:connect(KitchenEnter)
Kitchen2.Touched:connect(KitchenEnter)

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