Hi! I'm a beginner scripter so I don't know how to script well, I tried making this but it doesn't work.
local anim = "AnAnimation" while true do anim:Play() wait (0.99) wait (0.99) wait (0.99) end
Any help would be helpful, thankiew! :3
Run from a (Server) Script
local animation = script.Parent animation.AnimationId = "rbxassetid://0" local model = workspace:WaitForChild("Model") local animPlayer = model.Humanoid:LoadAnimation(animation) while true do if script.Parent.TurnOff.Value == false then animPlayer:Play() wait(2) else wait() end end
Notes
Line 1: Make sure "script.Parent" is an Animation within ServerScriptService
Line 2: Set this to the id number of the animation (you MUST own it) If you set this value on the animation itself in Studio, you can also just remove this line.
Line 3: Set "Model" to the name of the NPC Model
Line 4: Change this location (workspace.Model.Humanoid) to the NPC you want to animate
Line 7: This is a BoolValue named "TurnOff" that when set to true will end the animation, it is parented under the Animation
Line 9: The number in the wait(#) should be the amount of time the animation runs for (default of 2)
Explanation: You cannot just play an Animation, it must be loaded into the NPC and played from an Animation Track, which is automatically made when you load the Animation into the Humanoid
Serpentine's answer will work, but there is a more efficient way to do it (in my opinion).
Like he said, you have to load it into a humanoid first and play the AnimationTrack object it creates.
local animation = Instance.new("Animation", script.Parent) -- create a new anim. object animation.AnimationId = "rbxassetid://507766388" -- roblox idle anim local model = workspace:WaitForChild("Dummy") local AT = model.Humanoid:LoadAnimation(animation) -- load anim while true do AT:Play() At.Stopped:wait() -- wait for track to stop playing, then play again end
It utilizes the .Stopped event of the AnimationTrack, which waits for the animation to stop before proceeding.