How would I go about making my hiding system?

I’m making a game in which one of the core mechanics is hiding inside of lockers. I have my locker model and the open and close animations finished but I don’t know how to do this specific thing. I want to get every locker (in a folder called “Lockers”) and then get a specific part within that model that acts as a hitbox that counts you as hiding if you’re in contact with it and the door is closed. How would I get that part in a localscript so it works for every locker with one script?

This would be as easy as creating a script in the lockers doing the test on a hit box and the door state then setting a hide variable. What code have you created all ready? Why isn’t that posted?

I was wondering if there was a way to do it in one master script instead of having one copied into every box. I have an iteration with a script inside the box though it isn’t working

local DoorClosed = script.Parent.Parent.DoorClosed.Value
local Hiding = script.Parent.Parent.Hiding.Value

	until DoorClosed == true
	print("The door is closed")
	Hiding = true
	game.Workspace.CasualAmbience.HidingEffect.Enabled = true

loop through the lockers. something like

for i,v in pairs(lockerfolder:getchildren()) do
--hide function stuff

That’s a good idea, I tried and I get this.

There’s probably something really simple i’m not getting right

capitalize it to GetChildren(). i just didnt capitalize anything as i typed

Now it works but it triggers multiple times and it’s not constantly checking so even if i’m inside the box and close the door, hiding will never be true

Ya, but there is no need for that … and will just complicate everything. Short and sweet is always better. The scripts will eat up no* time sitting there un-activated.
*so little it will not matter.

Go watch the script usage on the console from game … they will not even show up till active.
I actually did something just like this (kinda) … and watched to make sure it wasn’t a mess.
Roblox is pretty advanced … got to give it some credit.

I don’t have any better ideas on how to do it but yeah it seems overly complex to have it in each and every one

It would be overly complex to have to figure out who and where someone out of everyone is now hiding in one script sweep. Why put yourself through that … :rofl: There is something to be said for a generic locker hide code. Don’t really matter how you get there as long as your there.

You could toss a attribute on the player and sweep for that … I guess
Player.Character:SetAttribute(“Hidden”, true)
If Player.Character:GetAttribute(“Hidden”) == true then
That would give you both things you need to know … who it is and if they are hidden

But you would need a script on the locker to do that anyways. So the one script could check for it.

yeah true I suppose individually would be the best way. i’m just not good with this so even that will take a good while of trial and error

Normally I would say no to that … But, like I said I’ve watched how that works in the console.
Roblox is doing way more than one would think. Things sitting there not fired really don’t eat up any* time at all.

I did this in one of my programs:
the _Shell script …

local scr = script.LootS
local from = workspace.Loot.Shells
for _, to in ipairs(from:GetDescendants()) do
	if to:IsA("Part") then
		if to.Name ~= ("Loot") then
			local clone = scr:Clone()
			clone.Parent = to
			clone.Disabled = false
end scr:Remove()

Kind of the best of both alternatives :rofl:
One generic script that got copied to all the shells, and all them other loots.

Yeah i’m trying something like that, It prints what I have here but when i’m inside and close the door the “Hiding” value doesn’t become true

local HideBox = script.Parent
local DoorClosed = script.Parent.Parent.DoorClosed.Value
local Hiding = script.Parent.Parent.Hiding.Value
db = true

for i,v in pairs(LockerFolder:GetChildren()) do
		local char = hit.Parent
		local hum = char:FindFirstChild("Humanoid")
		if hum and db then
		db = false
		print("Entered locker")
		if DoorClosed == true then
				Hiding = true

Ya, them hit boxes/checks don’t go off if you don’t move once you’re on it.
They could walk in stop then shut the door and it wouldn’t fire again unless they moved a bit in the locker. You’ll probably have to shut the door after they enter yourself. You’re not even going to be able to tell if they moved off or that was moving in.

the opening and closing is in another script I really don’t know how to do this. I wanted to try touchended for when they leave but i’m not sure how useful this would be i have no idea what I am talking about

Would have to set a different hit part outside the locker to see if they moved out.
This is what I was talking about when I said one script would be a nightmare.

Yeah that’d work would i have a seperate script in there or just handle that in my one hiding script in the locker? maybe have that part in the locker model

my problem is i only want hiding to be true if they’re inside AND if the door is closed i don’t want them to be able to sit inside with the door open and be okay

I assumed we were talking about a hit part inside this whole time … between the one inside and the one outside you should be able to determine where they are.

There is a hit part inside the locker I made it red here this is where i want the the character hiding to trigger if the door is closed

Ya this is getting complicated … Time to pull up the studio and do some test …