How to make a room-detecting script

For my game I’m trying to make a script which detects what room of the house you are in. So far I have done this: I first started placing blocks that are the size of the room they are in. I gave them all a script, so when the part gets touched it enables a boolean. Now what I’m trying to figure out is how to only have one boolean activated at a time. What happens with my current script is that each room you walk into the boolean gets enabled and never disabled, and I want to make it so when you step in another room the script of the room-detecting part is fired and enables its own boolean, while disabling every other boolean.

Here is my current code:

local part = script.Parent
local check = part.Parent.Bools:GetDescendants()
local bool = script.Parent.Parent.Bools:FindFirstChild(part.Name)

function InRoom()
	bool.Value = true
	print("Player is in", part.Name)
	local function Check()
		-- I don't know what to do here
	end
end

part.Touched:Connect(InRoom)

I don’t know how to do this, I’m not very experienced at scripting yet. I’m also not 100% sure if this is the right way to go about it, so I’ll be thankful for any help.

1 Like

Hmm… For me, actually i would do that: 1. Create a global script that connects every “hitbox” of the room. (not create many scripts for many rooms) 2. Create an attribute named “CurrentlyInRoom” in player and change it when player changes room.
This is solution i’ll use for this question.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.