Hello! I am modifying the default script in the linked sword gear to play My own animation. Everything is exactly the same except this part.
function attack() damage = slash_damage SlashSound:play() local anim = Instance.new("Animation") anim.Name = "toolanim" anim.AnimationId = "http://www.roblox.com/asset/?id=211308302" anim.Parent = Tool script.Parent.toolanim:Play() end
The animation will not play. In my out put it says: 19:00:42.155 - Play is not a valid member of Animation. I understand it is saying that it does not know what play is in the animation. What do I need to put there to make it play? Oh and the animation is just a simple customized hand swing, If that helps any.
Danke ~Minikitkat
The most important thing to note when playing animations is that you must load the animation.
You can do this by using the :LoadAnimation()
method. It accepts an animation object with a valid ID of your animation asset.
I'm not entirely sure what your scripting style is, but I prefer to define my variables at the beginning of my script, so that it's ready to use.
Assuming that your animation is not looped, that it's priority is high enough so that it's not overridden by Roblox's default animations, and that this script is a local script, you may try it this way.
char = game.Players.LocalPlayer.Character humanoid = char:WaitForChild("Humanoid") -- You may delete the first two lines if they're already defined. -- Be sure to replace the 'humanoid' variable to the desired Humanoid object in line 11 if you do. SlashAnim = Instance.new("Animation") SlashAnim.Name = "toolanim" SlashAnim.AnimationId = "http://www.roblox.com/asset/?id=211308302" SlashAnim.Parent = Tool SlashAnimLoaded = humanoid:LoadAnimation(SlashAnim) function attack() damage = slash_damage SlashSound:play() SlashAnimLoaded:Play() end
The reason why I didn't make a new animation in the function is because every time it is called, the script will make a new animation. So the amount of times the function is called is just as much as the animation objects your script will make.
I have been experiencing this issue to as well, but I found out it requires a ordinary script, not a module script and not a local script. If your still having trouble with using a ordinary script try removing or rescripting (if there is) any scripts that weld the character together, if you need the welding script inside the character to weld a model to its back, simply rescript it so that it will not interact with any parts of the body that require the animation (e.g The torso). >Hope this helped, sincerely HeComesAt_Night.