Animations being loaded synonymously are falling out of sync after a duration of time

I’m designing a game in which ‘‘Scenes’’ are taken from a folder in ReplicatedStorage and cloned into the Workspace for a duration of time. This action is done via a script in ServerScriptService. (The script below.)

local scenes = game.ReplicatedStorage.Scenes:GetChildren()

local currentScene = nil


task.wait(30)
while true do
	task.wait(2)
	print("Scene Cloned...")
	currentScene = scenes[math.random(1, #scenes)]:Clone()
	currentScene.Name = "CurrentScene"
	currentScene.Parent = workspace
	currentScene.SceneAudio.Sound:Play()

	task.wait(47)
	print("Scene Destroyed...")
if currentScene then
		currentScene:Destroy()
		task.wait(20)
	end
end

This script works in sync with another script in the Workspace. The script in the Workspace controls the opening/closing of the doors of an elevator, the music, and a few other aspects. However, over time, these scripts stop working in sync with each other. I’m not sure if this is due to the animations not being pre-loaded, or what a fix could be. Below is the script via the Workspace.

-- Main Game Script
local ElevatorDoor = game.Workspace.Elevator.FakeElevatorDoor
local ElevatorDing = game.Workspace.Sounds.ElevatorSpeaker.ElevatorDing
local ElevatorDoorOpenClose = game.Workspace.Sounds.ElevatorSpeaker.ElevatorDoorOpenClose
local ElevatorMusic = game.Workspace.Sounds.ElevatorSpeaker["Elevator Music"]
local ElevatorScript = game.Workspace.ElevatorDoorRig.Humanoid.ElevatorScript

task.wait(30)

--Elevator Loop
while true do
	ElevatorMusic:Stop()
	print("Elevator Doors Opening!")
	ElevatorDing:Play()
	task.wait(2)
	ElevatorDoorOpenClose:Play()
	task.wait(2)
	ElevatorScript.Disabled = false
	task.wait(45)
	ElevatorDoorOpenClose:Play()
	task.wait(3)
	print("Elevator Doors Closing!")
	ElevatorScript.Disabled = true
	ElevatorMusic:Play()
	task.wait(20)
end

one of your loops is 3s longer than the other.

I don’t see why they shouldn’t just go under the same script since you will run into problems like these whenever you try to change something.

Thank you. I figured that out after making this post. Putting them both under the same script fixed the issue. Cheers.