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.
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)
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.