I have a vault door that tweens open and closed with input from a player via a proximity prompt, as seen in the below code:
--- local script
local pp = game:GetService("ProximityPromptService")
pp.PromptTriggered:Connect(function(prompt: ProximityPrompt, playerWhoTriggered: Player)
if prompt.Parent then
if prompt.Name == "vaultDoor" then
local door = prompt.Parent.Parent
if door and door.Name == "armoryVaultDoor" then
replicatedStorage.events.server.vaultDoor:FireServer(door)
end
end
end
end)
---server script
ReplicatedStorage.events.server.vaultDoor.OnServerEvent:Connect(function(player: Player, door: Model)
if door:GetAttribute("inProgress") then return end
local x,y,z = door.PrimaryPart.CFrame:ToOrientation()
local info = TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
if door:GetAttribute("open") == true then
local old = Vector3.new(x,y-90,z)
tweenModule.TweenModuleOrientation(door,info,old,true,true)
else
local new = Vector3.new(x,y+90,z)
tweenModule.TweenModuleOrientation(door,info,new,true,false)
end
local sound = door:FindFirstChildWhichIsA("Sound",true)
if sound then
sound:Play()
end
end)
However, when opening closing, the door(s) never really close all the way, and a player can cause the doors to close even less properly, as seen below:
This was not an issue when I first tested this system, but that was when I tested it where the buildings these doors were in weren’t at certain angles, as seen with the placement system below:
I have no idea what the issue is, can someone help?
Here is the code that tweens the door open/closed:
function module.TweenModuleOrientation(Model,Tweeninfo,oOrinetation,isDoor,openStatus)
if typeof(Model) ~= "Instance" then error(Model.." isnt a instance") end
if not Model:IsA("Model") then error(Model.Name.." isnt a model") end
if not Model.PrimaryPart then Model.PrimaryPart = Model:FindFirstChildWhichIsA("BasePart") end
local prompt = Model:FindFirstChildWhichIsA("ProximityPrompt",true)
if isDoor then
if prompt then
prompt.Enabled = false
end
Model:SetAttribute("inProgress",true)
end
task.spawn(function()
local Primary = Model.PrimaryPart
local AnchorState = Primary.Anchored
local TW = TS:Create(Primary,Tweeninfo,{CFrame = Primary.CFrame * CFrame.Angles(math.rad(oOrinetation.X),math.rad(oOrinetation.Y),math.rad(oOrinetation.Z))})
for _,v in pairs(Model:GetDescendants()) do
if v:IsA("BasePart") and v ~= Primary then
local weld
if not v:FindFirstChild("TweenWeld") then
weld = Instance.new("WeldConstraint")
weld.Part0 = Primary
weld.Part1 = v
weld.Parent = v
weld.Name = "TweenWeld"
else
weld = v:FindFirstChild("TweenWeld")
weld.Enabled = true
end
local anchord = v.Anchored
v.Anchored = false
task.spawn(function()
TW.Completed:Wait()
weld.Enabled = false
v.Anchored = anchord
end)
continue
end
if v:IsA("Weld") or v:IsA("WeldConstraint") or v:IsA("ManualWeld") or v:IsA("Motor6D") then
if v.Name ~= "TweenWeld" then
v.Enabled = false
task.spawn(function()
TW.Completed:Wait()
v.Enabled = true
end)
end
continue
end
task.wait()
end
TW:Play()
TW.Completed:Wait()
if isDoor then
if openStatus then
prompt.ActionText = "Open"
Model:SetAttribute("open",nil)
else
prompt.ActionText = "Close"
Model:SetAttribute("open",true)
end
Model:SetAttribute("inProgress",nil)
if prompt then
prompt.Enabled = true
end
end
Primary.Anchored = AnchorState
end)
return
end
The above code is from here