Hi everyone, I’m hoping to get help with something I’ve been scratching my head over for a while. I have a door system which uses animations for doors (I’ve done this because I intend to have complex doors that couldn’t just rely on motors or tweens). Here is my issue: the first time you use the close animation it glitches. However, every time after that it is absolutely fine. However, it runs the same code so I’m quite confused.
I tried to fix this by using track.KeyframeReached for the close anim so it triggered when once it was closed but it caused other issues.
First time using door (not ok)
The rest of the time (absolutely fine)
Here is the code that runs every time the door is toggled:
function DoorController:ToggleDoor(door)
local animController = door:FindFirstChildOfClass("AnimationController")
if door:GetAttribute("State") == true then -- This bit runs when opening
local OpenAnim = door.OpenAnim
local OpenSound = door.OpenSound
local track = animController:LoadAnimation(OpenAnim)
local StaticAnim = door.StaticAnim
local staticTrack = animController:LoadAnimation(StaticAnim)
doorAnimations[door] = staticTrack
track:Play()
OpenSound:Play()
track.KeyframeReached:Connect(function(name)
if name == "Open" then
staticTrack:Play()
track:Destroy()
end
end)
else -- This bit runs when closing
local CloseAnim = door.CloseAnim
local CloseSound = door.CloseSound
local track = animController:LoadAnimation(CloseAnim)
track:Play()
CloseSound:Play()
doorAnimations[door]:Stop()
doorAnimations[door]:Destroy()
doorAnimations[door] = nil
end
end
Maybe I’m just being stupid but all help is appreciated