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

How do i make an animation play on click?

Asked by 4 years ago

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.

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
i should insert a script in the tool but where do i put the local script TheQuitzzyKadren 29 — 4y
0
You put the local script in the tool, animations are handled by LocalScripts, but if you want something that the server would handle, then add RemoteEvent/RemoteFunction then add a normal script. i don't think you need that since the strength part works perfectly fine so just put the local script in the tool and the serverscript in the tool, too. mudathir2007 157 — 4y
0
it didnt work... here is what i did. TheQuitzzyKadren 29 — 4y
0
can you tell me in a different way i didnt understand what you just said but this is the script i put local AnimObj = Instance.new("Animation",(script.Parent)) AnimObj.AnimationId = "rbxassetid//3508640924" local player = game:GetService("Players").LocalPlayer local AnimObj = workspace.AnimationA local char = player.Character or player.CharacterAdded:Wait() local humanoid = char:WaitForChild("Huma TheQuitzzyKadren 29 — 4y
View all comments (11 more)
0
remove 'localAnimObj = workspace.AnimationA' since you already created an animation object mudathir2007 157 — 4y
0
im not even decent at scripting and i need someone to teach me but nobody i know knows how to script so i just look at tutorials and they are useless too. So i dont know anything about scripting all i know are while loops functions remotes events and variables and prints and thats it so i just look up tutorials TheQuitzzyKadren 29 — 4y
0
ugh it says it failed to load TheQuitzzyKadren 29 — 4y
0
Sorry I did a typo, it's 'AnimTrack =' in the variables and not 'AnimTrac =' so change that once again sorry, just examine the script more, and read the entire answer over if you did not understand. mudathir2007 157 — 4y
0
And are you using your own animation? If you are using someone else's it won't work mudathir2007 157 — 4y
0
yes my own TheQuitzzyKadren 29 — 4y
0
Fixed that typo? (should be AnimationTrack =) and if you want to learn how to script then go watch those tutorials made by ROBLOX, also one thing, asking for scripts is against the rules as this website is mainly for solving user's script problems. mudathir2007 157 — 4y
0
yes TheQuitzzyKadren 29 — 4y
0
it still doesnt work TheQuitzzyKadren 29 — 4y
0
can you teach me how to script though? TheQuitzzyKadren 29 — 4y
0
Chat in the community chat, please we'll discuss it further mudathir2007 157 — 4y
Ad

Answer this question