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

Can someone tell me how to stop this animation?

Asked by 9 years ago

I finally did a script on my own, Even though I looked at free models and Forums to see how to put it together But here it is, please tell me how to stop the animation when I press Q again?

LOOK!! I already have the part where when I FIRST press Q The Animation DOES start(although my walkspeed doesnt change).. but when I press Q again IT DOESNT STOP, and my walkspeed doesnt change!! How do I MAKE IT STOP?!

wait(2)

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

Mouse.KeyDown:connect(function(key)
if key == "q" then
s = player.Character.Humanoid:LoadAnimation(game.StarterPack.AnimScrip.Animation)
script.Parent.Parent.Parent.Humanoid.Walkspeed = 22
s:Play()
elseif key == "q" then
s = player.Character.Humanoid:LoadAnimation(game.StarterPack.AnimScrip.Animation)
script.Parent.Parent.Parent.Humanoid.Walkspeed = 16
s:Stop()
end
end)

0
Yes, there are parentheses after the word "Animation" The lua just didnt show it on this website. 789zaya 0 — 9y
0
I edited this, from the code I just added.. 789zaya 0 — 9y

3 answers

Log in to vote
0
Answered by 9 years ago

Well, not sure, but i bet this works:

wait(1)

local player = game.Players.LocalPlayer
local isP = false
local Mouse = player:GetMouse()

Mouse.KeyDown:connect(function(key)
if key == "q" then
       if(isP==false)then isP=true
       local s = player.Character.Humanoid:LoadAnimation(game.StarterPack.LocalScript.Animation)
       s:Play() 
       else isP=false
       local s2 = player.Character.Humanoid:LoadAnimation(0)
       s2:Play()
       end
end
end)

Hope this helps! If not, tell output...

0
Alright, thanks! I'll test it out! 789zaya 0 — 9y
0
Sorry, but I keep seeing the little red line under *End" before the last "End" What IS WRONG THERE?! I told output, it said its expecting a function or something. What could be wrong? 789zaya 0 — 9y
0
Output says: 13:54:50.562 - Error in script: function arguments expected near 'end' 789zaya 0 — 9y
0
oops sorry! fixed marcoantoniosantos3 200 — 9y
View all comments (2 more)
0
Output is saying the same thing! This is frustrating.. 789zaya 0 — 9y
0
Damn you ScriptingHelpers.org for no coding like rbx studio! Well try now, coded in RBX Studio. marcoantoniosantos3 200 — 9y
Ad
Log in to vote
0
Answered by
Mystdar 352 Moderation Voter
9 years ago

You should search thoroughly though the wiki this website and other resources before asking a question here, it took me 2 minutes to find a similar question, of similar nature here.

Try this:

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
 s = player.Character.Humanoid:LoadAnimation(game.StarterPack.LocalScript.Animation) -- Define here

Mouse.KeyDown:connect(function(key)
    if key == "q" then -- Needed a tab here
        s:Play()
    end
end)

Mouse.KeyUp:connect(function(key)
    if key == "q" then -- Needed a tab here
        s:Stop()
    end 
end)
0
This was my first script, sorry. But what do you mean by needed a tab? And Define define you DO mean don't Define S in the function. Right? 789zaya 0 — 9y
0
Oh, and the second to last "End" on the bottom part of the script still has those red lines under it. I can't seem to get rid of them for Some reason... 789zaya 0 — 9y
Log in to vote
0
Answered by 9 years ago

Actually, Mystdar made a small mistake on line 13. Try this one:

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
 s = player.Character.Humanoid:LoadAnimation(game.StarterPack.LocalScript.Animation) -- Define here

Mouse.KeyDown:connect(function(key)
    if key == "q" then -- Needed a tab here
        s:Play()
    end
end)

Mouse.KeyUp:connect(function(key)
    if key == "q" then -- Needed a tab here
        s:Stop() -- forgot to put () after stop
    end 
end)
0
Thanks Mystdar 352 — 9y
0
And OUTPUT SAYS...! 10:35:30.525 - Players.Player1.Backpack.LocalScript:3: attempt to index field 'Character' (a nil value) 789zaya 0 — 9y
0
What do you mean by Define here? 789zaya 0 — 9y

Answer this question