Rooms locker code not delaying

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a working Rooms locker

  2. What is the issue? Include screenshots / videos if possible!
    I get trapped in the locker and am trying to fix it

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried delaying it.
    robloxapp-20240201-1435042.wmv (2.1 MB)

local Prox = script.Parent.Attachment.ProximityPrompt
local IsTaken = script.Parent["IsTaken?"]
local delay = false
---
Prox.Triggered:Connect(function(Plr)
	local Hum = Plr.Character:FindFirstChildOfClass("Humanoid")
	if Hum and IsTaken.Value == false and delay == false then
		delay = true
		IsTaken.Value = true
		Hum:AddTag("Hidden")
		Plr.Character.HumanoidRootPart.Anchored = true
		Plr.Character:PivotTo(script.Parent.CFrame)
		wait(0.2)
		delay = false
		Prox.Triggered:Connect(function(Plr2)
			if Plr2 == Plr and delay == false and IsTaken == true then
				delay = true
				IsTaken.Value = false
				Plr.Character.HumanoidRootPart.Anchored = false
				Hum:RemoveTag("Hidden")
				Plr.Character:PivotTo(script.Parent.Attachment.WorldCFrame)
				wait(0.2)
				delay = false
			end
		end)
	end
end)

Hey @Rhodizites when you try to exit the cabinet, it pops up some error? Have you tried debugging the code and seeing where the script doesn’t want to go next?

You are connecting one function inside another (not recommended), you should play with the “if” conditions.

local Prox = script.Parent.Attachment.ProximityPrompt
local IsTaken = script.Parent["IsTaken?"]
local delay = false
---
Prox.Triggered:Connect(function(Plr)
	local Hum = Plr.Character:FindFirstChildOfClass("Humanoid")
	
	if Hum and delay == false then
		delay = true
		if IsTaken.Value == false then -- hide the player
			IsTaken.Value = true
			Hum:AddTag("Hidden")
			Plr.Character.HumanoidRootPart.Anchored = true
			Plr.Character:PivotTo(script.Parent.CFrame)
			
		else -- player alr hidden, he is triggering again, so take him out.
			IsTaken.Value = false
			Hum:RemoveTag("Hidden")
			Plr.Character.HumanoidRootPart.Anchored = false
			Plr.Character:PivotTo(script.Parent.Attachment.WorldCFrame)
		end
		task.wait(0.2)
		delay = false
	end
end)

Now I am locked out again just like it was before I had the locking inside bug.

I don’t get one, I don’t know how you got it.

Also here is my entity code if you need it, I am using it to create the raycasting, hiding, etcetera.

local Art = script["A-60"].Art:GetChildren()
local Face
local PrevFace
local memeray
while wait() do
	if Face then
		PrevFace = Face
	end
	
	for i, face in pairs(script["A-60"].Art:GetChildren()) do
		if face:IsA("ImageLabel") then
				face.Visible = false
		end
	end
	while Face == PrevFace do
		Face = Art[math.random(1, #Art)]
	end
	Face.Visible = true
	for i, plr in pairs(game.Players:GetPlayers()) do
		if plr.Character then
			memeray = workspace:Raycast(script["A-60"].Position, plr.Character:WaitForChild("HumanoidRootPart").Position - script["A-60"].Position, RaycastParams.new()) --IMAFIREMAHLAZARRRRPOWWWAAWWWWWWWWWWWWWWWWWWWWWW
				if (memeray and memeray.Instance and memeray.Instance.Parent == plr.Character or memeray.Instance.Parent.Parent == plr.Character) and memeray.Distance <= 50 then
				if not plr.Character:FindFirstChildOfClass("Humanoid"):HasTag("Died") and not plr.Character:FindFirstChildOfClass("Humanoid"):HasTag("Hidden") then
					plr.Character:FindFirstChildOfClass("Humanoid"):TakeDamage(50)
					if plr.Character:FindFirstChildOfClass("Humanoid").Health <= 0 then
						workspace["A-60Kill"]:Play()
						for i, obj in pairs(plr.Character:GetChildren()) do
							if obj:IsA("BasePart") then
								obj.BrickColor = BrickColor.new("Really red")
							end
							if obj:IsA("MeshPart") then
								obj.TextureID = "rbxassetid://15904388916"
								obj.BrickColor = BrickColor.new("Really red")
							end
							if obj:IsA("Shirt") or obj:IsA("ShirtGraphic") or obj:IsA("Pants") then
								obj:Destroy()
							end
						end
						plr.Character:FindFirstChildOfClass("Humanoid"):AddTag("Died")
					end
					end
				end
			end
		end
	end

For the if statement in the second Triggered connection, I believe it should be IsTaken.Value == true instead of IsTaken == true.

if Plr2 == Plr and delay == false and IsTaken.Value == true then
1 Like

Ohhh you are right, i totally forgot about values!

1 Like

That might be the reason as to why you were being locked in.

1 Like

You are totally (not jokingly) right. I will try it.

It works! Thank you so much for the help, I really appreciate it!

1 Like

How do I tween a model --Now I need more help ;-;

1 Like

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