Lockdown Script Issue

Hello Developers, I’m trying to make a lockdown door that closes/opens when you trigger a proximity prompt. Here’s my code:

local Part = script.Parent
local Settings = require(script.Settings)
local Model = workspace.CautionModel
local Pos1 = Part.Position
local GroupID = 9395780
local Detector = workspace.ButtonHolder.Button.ProximityPrompt
local OpenButton = workspace.OpenButton.Button.ProximityPrompt
local db = false
local Open = true
local WaitTime = Settings.WaitTime
local Compressing = false
local Alarm = Part:WaitForChild("Alarm")
local PosToTween = Model.ChosenModel.ChosenTModel.Wedge.Position

local TweeningInfo = TweenInfo.new(
	30,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local TweenProperties1 = {
	Position = PosToTween
}

local TweenProperties2 = {
	Position = Pos1
}

local Tween1 = game.TweenService:Create(Part, TweeningInfo, TweenProperties1)
local Tween2 = game.TweenService:Create(Part, TweeningInfo, TweenProperties2)

Detector.Triggered:Connect(function(Player)
	if Player:GetRankInGroup(GroupID) >= 5 then
		if not db and Open then
			db = true
			Tween1:Play()
			Compressing = true
			Alarm:Play()
			Alarm.Playing = true
			print("Closing...")
			wait(14)
			Compressing = false
		    Tween1.Completed:Wait()
			wait(WaitTime)
			Open = false
			db = false
		elseif not db and not Open then
			db = true
			Tween2:Play()
			Compressing = false
			Alarm:Stop()
			Alarm.Playing = false
			print("Opening...")
			Tween2.Completed:Wait()
			wait(WaitTime)
			Open = true
			db = false
		else
			print(Player.Name.." cannot interact!")
		end
	end
end)

Part.Touched:Connect(function(Hit)
	local Character = Hit.Parent:FindFirstChild("Humanoid")
	if Character then
		print(Character.Parent.Name.." touched the door!")
		if Compressing then
			print("Killing "..Character.Parent.Name)
			Character.Health = 0
		end
	end
end)

OpenButton.Triggered:Connect(function(Player)
	if Player:GetRankInGroup(GroupID) >= 5 then
		if not db and not Open then
			db = true
			Tween2:Play()
			Compressing = false
			Alarm:Stop()
			Alarm.Playing = false
			print("Opening...")
			Tween2.Completed:Wait()
			wait(WaitTime)
			Open = true
			db = false
		else
			print(Player.Name.." cannot interact!")
		end
	end
end)


The Alarm sound plays, everything prints fine, but the door doesn’t tween properly. I know this isn’t the best code, but it worked before. Someone on my developer team tried it, and found that for some reason it didn’t work now. I’ve tried a lot of things, like putting a different part, setting the door’s CanCollide to false, etc. The strangest thing is when I put it in a while true do loop, the door closes properly.

1 Like

can you send screen shoot of output ?

Sure, but just to save time, everything prints perfectly.

and also screen shoot of explorer view can be good for understanding structure

image
image

when you open and closing door it prints to output, but door not moving, am i right ?

Yes.
(3-0 character filter - text)

local PosToTween = Model.ChosenModel.ChosenTModel.Wedge.Position

this present a position of door, can you inspect it ?

That is the position of the part I want the door to tween to.

is that position same with closed one ?

What about.

local TweenProperties2 = {
	Position = Vector3.new(Pos1)
}

its will be like
Vector3.new(Vector3.new())

The “Pos1” is a Vector? I didin’t noticed.

I don’t think that would be right. Since Pos1 is already a Vector 3 value, it’s defined as:

local Pos1 = Part.Position

can you try this CFrame version ?

local Part = script.Parent
local Settings = require(script.Settings)
local Model = workspace.CautionModel
local GroupID = 9395780
local Detector = workspace.ButtonHolder.Button.ProximityPrompt
local OpenButton = workspace.OpenButton.Button.ProximityPrompt
local db = false
local Open = true
local WaitTime = Settings.WaitTime
local Compressing = false
local Alarm = Part:WaitForChild("Alarm")

local TweeningInfo = TweenInfo.new(30,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local Tween1 = game.TweenService:Create(Part, TweeningInfo, {["CFrame"] = Model.ChosenModel.ChosenTModel.Wedge.CFrame})
local Tween2 = game.TweenService:Create(Part, TweeningInfo, {["CFrame"] = Part.CFrame})

Detector.Triggered:Connect(function(Player)
	if Player:GetRankInGroup(GroupID) < 5 then return end
	if db then return end
	db = true
	if Open then
		Tween1:Play()
		Compressing = true
		Alarm:Play()
		Alarm.Playing = true
		print("Closing...")
		wait(14)
		Compressing = false
		Tween1.Completed:Wait()
		wait(WaitTime)
		Open = false
	elseif not Open then
		Tween2:Play()
		Compressing = false
		Alarm:Stop()
		Alarm.Playing = false
		print("Opening...")
		Tween2.Completed:Wait()
		wait(WaitTime)
		Open = true
	else
		print(Player.Name.." cannot interact!")
	end
	db = false
end)

Part.Touched:Connect(function(Hit)
	local Character = Hit.Parent:FindFirstChild("Humanoid")
	if not Character then return end
	print(Character.Parent.Name.." touched the door!")
	if not Compressing then return end
	print("Killing "..Character.Parent.Name)
	Character.Health = 0
end)

OpenButton.Triggered:Connect(function(Player)
	if Player:GetRankInGroup(GroupID) < 5 then return end
	if db then return end
	db = true
	if not Open then
		Tween2:Play()
		Compressing = false
		Alarm:Stop()
		Alarm.Playing = false
		print("Opening...")
		Tween2.Completed:Wait()
		wait(WaitTime)
		Open = true
	else
		print(Player.Name.." cannot interact!")
	end
	db = false
end)

This code isn’t working.
(3-0 char)

Bumping post, still need help with this.

What if you try to do this

local TweenProperties1 = {}
TweenProperties1.Position = PosToTween

And this

local TweenProperties2 = {}
TweenProperties2.Position = Pos1

Add a print after Tween2.Completed:Wait()
like: print(Tween2.PlaybackState)
and… when the code worked, was only one part inside the model? or more than one part?

for example the door were a part or just a mesh, maybe OR multiple parts that make up the door

When the code worked, it tweened the exact same part. I’m pretty sure no one even touched the script or model or anything. The only change was the button which triggers it, but it’s not even relevant since the only thing used from the button in that is the Proximity Prompt and Name, which still worked.