I need to use an animation for my script. The animation object is in ReplicatedStorage and I declare it in a variable at the Top of my script.
local Animations = ReplicatedStorage:WaitForChild("Animations")
local idleFly = Animations:WaitForChild("fly")
But this doesn’t work on its own. It does work however when I add this simple line just before it:
char:WaitForChild("movement"):WaitForChild("anim")
local Animations = ReplicatedStorage:WaitForChild("Animations")
local idleFly = Animations:WaitForChild("fly")
or also like this:
task.wait(1)
local Animations = ReplicatedStorage:WaitForChild("Animations")
local idleFly = Animations:WaitForChild("fly")
I don’t understand what the script actually needs to wait for. The anim object Parented to movement that is inside the character has no relation to this script whatsoever, so I assume that waiting for that loads the actual thing it needs to load to play the animation. So how would I make the animation load without waiting for the anim object?
Sure I could, but is it necessary? It’s a pretty long script and the animation is just played at the beginning.
Here’s a simplified version of the script:
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator") :: Animator
char:WaitForChild("movement"):WaitForChild("fly")
local Animations = ReplicatedStorage:WaitForChild("Animations")
local idleFly = Animations:WaitForChild("fly")
local function playAnimObj(anim)
local track = animator:LoadAnimation(anim)
track:Play()
end
local function characterInit()
hum.AutoRotate = false
hum:ChangeState(Enum.HumanoidStateType.Physics) --Enum.HumanoidStateType.PlatformStanding
playAnimObj(idleFly)
end
module.start = function(newConstants, newKeybinds)
if started then return end
constants = newConstants or constants
keyBinds = newKeybinds or keyBinds
characterInit()
started = true
end