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)

3 comments
Thank You, but I changed the question a bit. Does this still apply?
Yes it still applies.
Oh the post just updated for me. You can use the Humanoid.Running event to detect when the player starts and stops running.