So I have this NPC and want to make it do several animations, but it seems that its not doing it. This is my script:
local dummy = workspace:WaitForChild("Dummy")
dummy.Name = game.Players.LocalPlayer.Name
local humanoid = dummy.Humanoid:Clone()
dummy.Humanoid:Destroy()
humanoid.Parent = dummy
humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(game.Players.LocalPlayer.UserId))
local controller = game.Workspace[game.Players.LocalPlayer.Name].Humanoid
local AnimCall = Instance.new("Animation")
local randomVars = {"http://www.roblox.com/asset/?id=3337994105", "http://www.roblox.com/asset/?id=5938365243", "http://www.roblox.com/asset/?id=5938394742"} -- put the variables in a table
while true do
local randomVar = randomVars[math.random(#randomVars)] -- picking a random variable from the table
print(randomVar)
AnimCall.AnimationId = randomVar
local Call = controller:LoadAnimation(AnimCall)
Call:Play()
wait(10)
end
This is a LocalScript inside StarterCharacterScripts
Hope someone know how to fix this, Thanks!
You might want to replace those with rbxassetid://"youridhere".
You could also try switching the LocalScript’s parent to the player’s Backpack or PlayerScripts.
Oh yea, i forgot to tell you that the animation is working, but only 1 animation is playing everytime, I want it to be like the first time it play a, next play c then a then b like that, but now, it just keep playing a all the time
No, you could simply use AnimationTrack.Stopped:Wait().
while true do
local randomVar = randomVars[math.random(#randomVars)] -- picking a random variable from the table
print(randomVar)
AnimCall.AnimationId = randomVar
local Call = controller:LoadAnimation(AnimCall)
Call:Play()
Call.Stopped:Wait()
Call:Stop()
end
Weird. I rewrote it to make it clearer. Also, if you want this to be visible by every players, you might want to transfer this into a Server Script, with some modifications.
local dummy = workspace:WaitForChild("Dummy")
local humanoid = dummy:WaitForChild("Humanoid")
humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(game.Players.LocalPlayer.UserId))
local animation = Instance.new("Animation", dummy)
local animations = {
"http://www.roblox.com/asset/?id=3337994105",
"http://www.roblox.com/asset/?id=5938365243",
"http://www.roblox.com/asset/?id=5938394742"
}
while true do
local randomVar = animations[math.random(1, #animations)]
animation.AnimationId = randomVar
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack:Play()
animationTrack.Stopped:Wait()
animationTrack:Stop()
end
But then the avatar can only be 1 right? I mean, for example you have 2 player, a and b
for a, it shows his avatar, and for b it also shows a’s avatar right?
Because its a server script