I'm making a weight lifting simulator game cause I've never made a simulator before but I just cant figure out how to make it when I click I gain strength and the animation plays I already did the strength part it works perfectly fine its that I don't know how to do the animation and I'm a decent scripter not an advanced or good one.
To make an animation, you need an animation object. If you want to learn more about animation tracks, click here
Use LocalScript
& add script to tool
I'm going to explain everything with detail so that I'm not just throwing in a script.
If you don't already have animation object then do add one or add a variable like this to create one.
local AnimObj = Instance.new("Animation", (Choose parent)) AnimObj.AnimationId = "rbxassetid://Your Animation ID from URL"
To get animation track, you need to have an animation object. You might already have that. If so, then locate your animation and make it a variable. Also player. For example,
local player = game:GetService("Players").LocalPlayer local AnimObj = workspace.AnimationA -- if you already have animation object
And then you can find Character from LocalPlayer. Also Humanoid
is needed. Once again, this is a LocalScript
local player = game:GetService("Players").LocalPlayer local AnimObj = workspace.AnimationA local char = player.Character or player.CharacterAdded:Wait() local humanoid = char:WaitForChild("Humanoid")
Now we need an AnimationTrack, so, let's create a new variable.
local player = game:GetService("Players").LocalPlayer local AnimObj = workspace.AnimationA local char = player.Character or player.CharacterAdded:Wait() local humanoid = char:WaitForChild("Humanoid") local AnimTrac = humanoid:LoadAnimation(AnimObj)
Time to set Priority to Movement, so it plays over the original holding animtion, if you already did this in Animation editor then good, but if you didn't, there's a property in AnimationTrack
which is Priority, so add this to the script:
AnimTrack.Priority = Enum.AnimationPriority.Movement -- do movement or action, i recommend movement if you want something else to play on top of it
Finally, let's use the Tool.Activated
event and play animation. That's when the player clicks. If you want to learn more then click here.
AnimTrack.Priority = Enum.AnimationPriority.Movement -- do movement or action, i recommend movement if you want something else to play on top of it script.Parent.Activated:Connect(function() AnimTrack:Play() end
You can add debounce
if you want, but i'll leave it here, you can add what you want, I hope you learned something new, and I hope this worked for you.