I keep getting this error whenever I attempt to call :LoadAnimation() on the humanoid. The localscript is located in the player’s StarterPack. Here’s the code:
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local hum = char:WaitForChild("Humanoid")
local root = char:WaitForChild("HumanoidRootPart")
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/Asset?ID=180436334
local animTrack = hum:LoadAnimation(anim)
As you can see, I wait for the humanoid to exist, yet I still get the error. It only seems to happen in Studio, but it’s really hindering when you want to test. Here’s a repro:
Yeah, it is. I realise there are ways to work around the issue, like using the code you posted, however it only started happening recently as I’ve used the code in OP for ages now without any problems. That being said, most people, including myself, don’t like to use workarounds so I figured this would be an issue worth looking into.
Yeah, the problem here is that the DataModel (“game” object) isn’t global, and since services are parented to DataModel, you can’t use services without having a DataModel. LoadAnimation and a number of other API members need one or more of those services, so they can’t function without a DataModel either.
I wish this weren’t an issue because parent restrictions like this require hacky workarounds (e.g. I have to either parent entities to workspace as soon as I create them to load animations instead of letting the script that created them do the parenting, or have the scripts ask the entity to set its own parent where I can load animations there.), but I guess we’re stuck with it for now.