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

I've almsot perfected it PLEASE help with this ONE PROBLEM?! (SOLVED)

Asked by 9 years ago

Ok I AM ALMOST DONE WITH THIS ANIMATION SCRIPT!! JUST 1 MORE PROBLEM!!

People love Thumbing down my questions as if I've done something wrong.. and it's annoying... when I ask a question someone thumbs down of course and they dont even bother to answer.

Ok I made this and, when I press and Hold Q my WalkSpeed goes to 30 like I'm asking it to, AND my run animation starts! So, the first part is perfect.. but when I Release Q My Walkspeed Returns to 16 as it should but my animation doesnt stop! How do I stop it?!

wait(2)

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local humanoid = player.Character.Humanoid --Humanoid

Mouse.KeyDown:connect(function(key)
if key:lower() == "q" and humanoid then --I added ":lower()" incase they had caps lock on. I also added "and humanoid" just to see if it exists.
    s = humanoid:LoadAnimation(game.StarterPack.AnimScrip2.Animation)
    s:Play()
    humanoid.WalkSpeed = 30 --Change the speed
end
end)


Mouse.KeyUp:connect(function(key)
    if key:lower() == "q" and humanoid then
        s = humanoid:LoadAnimation(game.StarterPack.AnimScrip2.Animation)
        s:Stop()
        humanoid.WalkSpeed = 16
    end
end)
0
try making the "s" variable global. woodengop 1134 — 9y

1 answer

Log in to vote
2
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

Make your animation variable s global.

repeat
    wait()
until game.Players.LocalPlayer

player = game.Players.LocalPlayer
character = player.Character
if not character then
    character = player.CharacterAdded:wait()
end

Mouse = player:GetMouse()
humanoid = character:WaitForChild("Humanoid")
s = humanoid:LoadAnimation(game.StarterPack.AnimScrip2.Animation)

-- It's best if this variable was global, because then the script would be able to refer to the animation more efficiently.

-- Every time you load an animation to a variable, it inserts a new Animation instance in the Humanoid to be played. Kind of like "holding" an animation in the Humanoid.

-- So if you used your script & when you click "q" & release it, the Animation instance that's loaded in your Humanoid will be created 2 times, since you loaded it twice (through your .KeyDown/.KeyUp functions).

-- But in this script, the animation is loaded only ONCE.

Mouse.KeyDown:connect(function(key)
    if key:lower() == "q" then
        s:Play()
        humanoid.WalkSpeed = 30
    end
end)


Mouse.KeyUp:connect(function(key)
    if key:lower() == "q" then
        s:Stop()
        humanoid.WalkSpeed = 16
    end
end)
0
You beat me :( woodengop 1134 — 9y
0
xD Sorry. Redbullusa 1580 — 9y
0
I do like Bumping up your Reputation tho. woodengop 1134 — 9y
0
Thanks for your help! And thanks to the people that tried! 789zaya 0 — 9y
Ad

Answer this question