Code works in studio but not in game


		-- Get the appropriate animation script based on the rig type
		local animateScript = Model:WaitForChild("Animate")
		local newScript = animateScript:Clone()
		repeat wait() until newScript
		animateScript:Destroy()
		-- Rename the cloned script to "Animate"
		newScript.Name = "AnimateSCript"
		newScript.Parent = Model
		
		Model:WaitForChild("AnimateSCript")
		print("Animate found")

		AddToViewportFrame(Model)

I’m pretty much trying to clone and use the animate script, but it does not work in-game, only in studio. Why?

There is only the error which I’ve attached, but nothing else is mentioned.

Using :WaitForChild() after parenting the script to it isn’t needed.

It seems you attached the wrong error line, that’s the stack showing where the error came from. What was the error itself? (It also appears the error comes from inside the cloned script, seeing that code would help too)

I’ve tried doing wait for child to see if the code was actually trying to access it before it existed.

But this is actually not an error on my end, it rather seems to be a problem when you use CreateHumanoidModelFromDescription

A lot of posts have been talking about the same issue, it seems to be a problem that hasn’t been fixed yet:

And the best explained thread is:

That is the only error line in console, so I can’t really show the stack when there is none