#Door doesn't open after first click, but it works fine after that
3 messages · Page 1 of 1 (latest)
local TweenService = game:GetService("TweenService")
local ServerStorage = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")
local AnimsFolder = ServerStorage:WaitForChild("Animations")
local Animation = AnimsFolder:WaitForChild("OpenDoor")
local SoundsFolder = ServerStorage:WaitForChild("Sounds")
local Sound = SoundsFolder.OpenDoor
local Debounce = false
local function Sounds(model)
local ClonedSound = Sound:Clone()
ClonedSound.Parent = model
ClonedSound:Play()
ClonedSound.Stopped:Connect(function()
Debris:AddItem(ClonedSound)
end)
end
local DoorsFolder = workspace:WaitForChild("Doors")
local function OpenDoor(hinge, MainDoor, prompt, OrientationY, model)
local OpenDoorTrack
local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0,OrientationY,0)
local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
local tweenInfo = TweenInfo.new(0.5)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)
prompt.Triggered:Connect(function(player)
local char = player.Character
local hum = char:WaitForChild("Humanoid")
OpenDoorTrack = hum:LoadAnimation(Animation)
if not Debounce then
tweenOpen:Play()
prompt.Enabled = false
tweenOpen.Completed:Connect(function()
Debounce = true
prompt.Enabled = true
end)
OpenDoorTrack:Play()
Sounds(model)
prompt.ActionText = "Open"
else
tweenClose:Play()
prompt.Enabled = false
tweenClose.Completed:Connect(function()
Debounce = false
prompt.Enabled = true
end)
OpenDoorTrack:Play()
Sounds(model)
prompt.ActionText = "Close"
end
end)
end
for _, v in pairs(DoorsFolder:GetDescendants()) do
if v:IsA("Model") then
local Hinge = v:WaitForChild("Hinge")
local DoorMain = v:WaitForChild("MainDoor")
local Prompt = DoorMain.OpenPrompt
local RotationValue = v:WaitForChild("OrientationValue")
local Value = v.OrientationValue.Value.Y
OpenDoor(Hinge, DoorMain, Prompt, Value, v)
end
end