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

Why does Animation still play when I am standing completely still?

So I've loaded an animation onto my character and I want it to play when I am "Sprinting"(when I press LeftControl), but the animation still plays when I am standing still. How do I stop the animation when I am standing completely still? Do I have to play an idle animation?

Script:

local uis = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local sprinting = false
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/Asset?ID=4835831357"
PlayAnim = Player.Character.Humanoid:LoadAnimation(anim)

uis.InputBegan:Connect(function(key, processed)
    if processed then return end 
    if key.KeyCode == Enum.KeyCode.LeftControl and not sprinting then
		sprinting = true
		script.Parent.Humanoid.WalkSpeed = 26
		PlayAnim:Play()
		
	elseif key.KeyCode == Enum.KeyCode.LeftControl and sprinting then
		sprinting = false 
		script.Parent.Humanoid.WalkSpeed = 16
		PlayAnim:Stop()
	end
end)

1 answer

You have to stop the animation using animTrack:Stop() when the player stops sprinting. You have to also adjust the speed of your animation manually using animTrack:AdjustSpeed(x) where x is the percentage speed of the animation, e.g. when x = 1, the animation speed will be normal, and when x = 2, the animation speed will be twice as fast.

Here's the wiki link on AdjustSpeed: https://developer.roblox.com/en-us/api-reference/function/AnimationTrack/AdjustSpeed

3 comments

0

Thank You, but I changed the question a bit. Does this still apply?

0

Yes it still applies.

0

Oh the post just updated for me. You can use the Humanoid.Running event to detect when the player starts and stops running.

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