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)