Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Change run animation with the click of a GUI button?

This is the script I have right now, but it doesn't change the run animation when clicked. What am I doing wrong?

script.Parent.MouseButton1Click:connect(function(p)
p.Character.Animate.run.RunAnim.AnimationId = "http://www.roblox.com/asset?id=1889592040"
end)

7 comments

0

have it do the animation from the Humanoid instead of the Character because the Humanoid controls animations for the Character not the Character itself

0

How would I do that? Change "Character" to "Humanoid" in the script?

0

p.Character.Humanoid.RunAnim.AnimationId i think

0

Doesn't work :/

0

hmmm

0

have it check for Humanoid.Running then change the ID

0

How would I do that?local h = p.Parent:FindFirstChild('Humanoid') if h then ?

2 answers

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset?id=1889592040"
script.Parent.MouseButton1Click:connect(function()
local animTrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(animation)
animTrack:Play()
end)

I stole the scripting from the Roblox wiki, so I'm not 100% sure it'll work.

5 comments

1

Gives an error on the last " mark, not sure what I'm supposed to put inside those last parantheses?

0

Oops, just remove the last quotation mark.

1

the animation does not have a Parent you idiot xD

0

I don't think it needs a .Parent

0

It does need a Parent in order to be created.

I fixed it, this should work:

script.Parent.MouseButton1Click:connect(function(p)
local AnimationId = "1889592040" --set animation id here
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://"..AnimationId
local k = p.Character.Humanoid:LoadAnimation(Anim)
k:Play()
k:AdjustSpeed(2) --set animation speed here
end)

Tell me if it's broken or not.

1 comment

0

MouseButton1Click doesn't return anything, so you have to use localplayer

This discussion is preserved as it was. New answers, comments, and votes are closed.