Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

This Script works in studio but not in game?

So it makes the NPC Dance but it doesnt work in game..only on studio it works?

local animation = script.Animation
local animController = script.Parent.AC
local animTrack = animController:LoadAnimation(animation)
animTrack:Play()

2 answers

Are you using a Server Side script, or a Local Script? If your using a Server Side script, it's not going to work. Your referring to the player obviously, and the player is not exactly in the server, its on the local side, your side. If you put it in a Server Script(which is basically called a Script) it can't refer to it. It doesn't work in servers and only works in Studio because in Studio, its not running the game on the ROBLOX servers but on your computer. When you play in a normal server its running in the ROBLOX servers. That is why things work differently.

To fix it, change the script to a LocalScript.

Your welcome.

2 comments

0

I'm not sure that's his problem, it's more about Animation being null while he tries to access it, he just needs to add a FindFirstChild or a WaitForChild ;)

0

Well no need to down vote it jeez, I'm just trying to help

Whilst in studio the scripts load after all instances are loaded, on the server it loads before all instances, so it's fixed by simply adding a WaitForChild("")

WaitForChild("") is a pre-built function in all kind of Instances in roblox, wich waits for an Instance to load, being basically this:

function WaitForChild(part,ins)
while (part:FindFirstChild(ins)==nil) do wait() end
return ins
end

So you only need to do this:

local animation = script:WaitForChild('Animation')
local animController = script.Parent:WaitForChild('AC')
local animTrack = animController:LoadAnimation(animation)
animTrack:Play()

2 comments

2

Whlist you answered his question, saying "The problem is obvious." is one of the most derogatory and arrogant things you can say; specifically to a person who is learning how to code.

0

u.u Sorry, It's just my opinion on myself DX, I'll correct this.

This discussion is preserved as it was. New answers, comments, and votes are closed.