Wardrobe System Player still being able to go in locker even do its occupied

Hello i have made a working wardrobe system and i made a occupied value which will make the wardrobe script return end if true for the other player trying to get in the wardrobe when there is another player in it but for some reason when my other player tries to get in it will not return end and the player will be able to go in the wardrobe with the other player and i don’t know how to fix it so help is very appreciated.

Here is my script:

-- Services
local TS = game:GetService("TweenService")

-- Parts
local Wardrobe = script.Parent
local door1 = script.Parent.Primary1
local door2 = script.Parent.Primary2
local prompt = script.Parent.Box.ProximityPrompt

-- Values
local Occupied = script.Parent.Occupied

local function TweenModel(model,endf,t)
	spawn(function()
		local cframe_value = Instance.new("CFrameValue")
		cframe_value.Value = model.CFrame
		
		cframe_value:GetPropertyChangedSignal("Value"):Connect(function()
			model.CFrame = cframe_value.Value
		end)
		
		TS:Create(cframe_value,TweenInfo.new(t),{Value = endf}):Play()
		game.Debris:AddItem(cframe_value,t)
	end)
end


prompt.Triggered:Connect(function(player)
	if Occupied.Value == true then return end
	
	if prompt.ActionText == "Open"then
		
		local enter_locker = true -- = false

		local character = player.Character
		local hrp = character:FindFirstChild("HumanoidRootPart")

		if enter_locker and enter_locker == true then
			prompt.ActionText = "Close"
			enter_locker = false -- = true
			script.Parent.SoundEnter:Play()
			
			hrp.Anchored = true
			Occupied.Value = true
			
			TweenModel(door1,door1.CFrame*CFrame.Angles(0,30,0),0.5)
			TweenModel(door2,door2.CFrame*CFrame.Angles(0,-30,0),0.5)

			spawn(function()
				wait(0.25)
				TS:Create(hrp,TweenInfo.new(0.5),{CFrame = Wardrobe.Center.CFrame}):Play()
				wait(0.2)
				
				TweenModel(door1,door1.CFrame*CFrame.Angles(0,-30,0),0.5)
				TweenModel(door2,door2.CFrame*CFrame.Angles(0,30,0),0.5)
			end)
		end
	end
end)

prompt.Triggered:Connect(function(player)
	if Occupied.Value == false then return end

	if prompt.ActionText == "Close" then

		local enter_locker2 = true -- = false

		local character = player.Character
		local hrp = character:FindFirstChild("HumanoidRootPart")

		if enter_locker2 and enter_locker2 == true then
			prompt.ActionText = "Open"
			enter_locker2 = false -- = true
			script.Parent.SoundExit:Play()

			TweenModel(door1,door1.CFrame*CFrame.Angles(0,30,0),0.5)
			TweenModel(door2,door2.CFrame*CFrame.Angles(0,-30,0),0.5)

			spawn(function()
				wait(0.25)
				TS:Create(hrp,TweenInfo.new(0.5),{CFrame = Wardrobe.Exit.CFrame}):Play()
				wait(0.2)
				Occupied.Value = false
				hrp.Anchored = false
				
				TweenModel(door1,door1.CFrame*CFrame.Angles(0,-30,0),0.5)
				TweenModel(door2,door2.CFrame*CFrame.Angles(0,30,0),0.5)
			end)
		end
	end
end)

Have you done some debugging and see how it works and maybe you can see what’s wrong

1 Like

there are no errors in the output and the value is checked when u are in the locker so it must be the return end that isn’t working but it is working when i test it with no other players

if not Occupied.Value then
--code
else
return
end
1 Like

let me test this also im sorry i didn’t answer i was at football training and then i forgot all about it

1 Like

how would i be able to add it to the exit code because when i tested it with my exit code then the other player would still be able to run the exit code even do there is a player in the locker and the other player isn’t

Wdym by “exit code” could you show it to me?

1 Like

here is the whole code the exit code is at the bottom and it is highligthed with the --[[ --]]

-- Services
local TS = game:GetService("TweenService")

-- Parts
local Wardrobe = script.Parent
local door1 = script.Parent.Primary1
local door2 = script.Parent.Primary2
local prompt = script.Parent.Box.ProximityPrompt

-- Values
local Occupied = script.Parent.Occupied

local function TweenModel(model,endf,t)
	spawn(function()
		local cframe_value = Instance.new("CFrameValue")
		cframe_value.Value = model.CFrame
		
		cframe_value:GetPropertyChangedSignal("Value"):Connect(function()
			model.CFrame = cframe_value.Value
		end)
		
		TS:Create(cframe_value,TweenInfo.new(t),{Value = endf}):Play()
		game.Debris:AddItem(cframe_value,t)
	end)
end


prompt.Triggered:Connect(function(player)
	if not Occupied.Value then
		if prompt.ActionText == "Open"then

			local enter_locker = true -- = false

			local character = player.Character
			local hrp = character:FindFirstChild("HumanoidRootPart")

			if enter_locker and enter_locker == true then
				prompt.ActionText = "Close"
				enter_locker = false -- = true
				script.Parent.SoundEnter:Play()

				hrp.Anchored = true
				Occupied.Value = true

				TweenModel(door1,door1.CFrame*CFrame.Angles(0,30,0),0.5)
				TweenModel(door2,door2.CFrame*CFrame.Angles(0,-30,0),0.5)

				spawn(function()
					wait(0.25)
					TS:Create(hrp,TweenInfo.new(0.5),{CFrame = Wardrobe.Center.CFrame}):Play()
					wait(0.2)

					TweenModel(door1,door1.CFrame*CFrame.Angles(0,-30,0),0.5)
					TweenModel(door2,door2.CFrame*CFrame.Angles(0,30,0),0.5)
				end)
			end
		end
	else
	return
	end
end)

--[[ prompt.Triggered:Connect(function(player)
	if Occupied.Value then
		if prompt.ActionText == "Close" then

			local enter_locker2 = true -- = false

			local character = player.Character
			local hrp = character:FindFirstChild("HumanoidRootPart")

			if enter_locker2 and enter_locker2 == true then
				prompt.ActionText = "Open"
				enter_locker2 = false -- = true
				script.Parent.SoundExit:Play()

				TweenModel(door1,door1.CFrame*CFrame.Angles(0,30,0),0.5)
				TweenModel(door2,door2.CFrame*CFrame.Angles(0,-30,0),0.5)

				spawn(function()
					wait(0.25)
					TS:Create(hrp,TweenInfo.new(0.5),{CFrame = Wardrobe.Exit.CFrame}):Play()
					wait(0.2)
					Occupied.Value = false
					hrp.Anchored = false

					TweenModel(door1,door1.CFrame*CFrame.Angles(0,-30,0),0.5)
					TweenModel(door2,door2.CFrame*CFrame.Angles(0,30,0),0.5)
				end)
			end
		end
	end
end) --]]

You’re making variables inside the proximity prompt, that’s no good. I also see that you’re making 2 variables while you cause one of them.

1 Like

but how would i be able to make it so only the player which is in the wardrobe would be able to run the exit code?

Make a stringvalue and then when they get in, copy their username on the sstringvalue and then when you exit out of it you can see if the player name matches on the string value and if not then it does nothing.

1 Like

how do i fix this error value is not a valid member of player?

Could you at least show me the line of the code and the error.

1 Like

wait i fixed it


accidently said .value when i was supposed to say owner == player

thank you so much for your help it works now

1 Like