Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
CodyDev 70
6 years ago

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.

0
You can use the Touched event or Region3 to check if their character is inside a certain area. F_F 53 — 6y
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. GiveMeYourPudding 64 — 6y
0
Thanks, haven't tried this yet but I'm sure it'll work. CodyDev 70 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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)
Ad

Answer this question