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

Can someone tell me how to stop this animation?

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)

2 comments

0

Yes, there are parentheses after the word "Animation" The lua just didnt show it on this website.

0

I edited this, from the code I just added..

3 answers

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...

6 comments

0

Alright, thanks! I'll test it out!

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?

0

Output says: 13:54:50.562 - Error in script: function arguments expected near 'end'

0

oops sorry! fixed

0

Output is saying the same thing! This is frustrating..

0

Damn you ScriptingHelpers.org for no coding like rbx studio! Well try now, coded in RBX Studio.

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)

2 comments

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?

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...

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)

3 comments

0

Thanks

0

And OUTPUT SAYS...! 10:35:30.525 - Players.Player1.Backpack.LocalScript:3: attempt to index field 'Character' (a nil value)

0

What do you mean by Define here?

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