Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This Script works in studio but not in game?

Asked by
22To 70
8 years ago

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

Log in to vote
0
Answered by 8 years ago

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.

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 ;) marcoantoniosantos3 200 — 8y
0
Well no need to down vote it jeez, I'm just trying to help OMEGA27304 8 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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
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. Mystdar 352 — 8y
0
u.u Sorry, It's just my opinion on myself DX, I'll correct this. marcoantoniosantos3 200 — 8y

Answer this question