So i want the player to play an animation while he is sprinting but if he stops he goes in idle, i am using the CTRL key for this, you enable and disable sprinting with it, i don't really know how to do it correctly, i tried doing Humanoid.Running or changing the animate script inside the Character but sometimes it doesn't work correctly, how can i do it right?
If i directly try to play the animation once the Sprinting is turned on, the animation will be on a loop, so if the player stops the animation will still play
Local Script - (Inside StarterCharacterScripts)
local Character = script.Parent.Parent or script.Parent.Parent:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")
local Animation = Humanoid:LoadAnimation(script:WaitForChild("Animation"))
local UIS = game:GetService("UserInputService")
local IsBlocking = script.Parent:WaitForChild("ValueChecks"):WaitForChild("IsBlocking")
local IsDashing = script.Parent:WaitForChild("ValueChecks"):WaitForChild("IsDashing")
local RS = game:GetService("ReplicatedStorage")
local Activated = false
local Check = true
UIS.InputBegan:Connect(function(input, IsTyping)
if Activated == false then
if Check == true and IsTyping == false then
if input.KeyCode == Enum.KeyCode.LeftControl then
if IsDashing.Value == false and IsBlocking.Value == false then
Check = false
Activated = true
Humanoid.WalkSpeed = Humanoid.WalkSpeed * 2
end
end
end
end
end)
UIS.InputBegan:Connect(function(input, IsTyping)
if Activated == true then print("h1")
if IsTyping == false then
if input.KeyCode == Enum.KeyCode.LeftControl then
if IsDashing.Value == false and IsBlocking.Value == false then
Activated = false
Humanoid.WalkSpeed = Humanoid.WalkSpeed / 2
wait(0.5)
Check = true
end
end
end
end
end)

1 comment
you can use the InputEnded event which is apart of UserInputService and check if the key is CTRL. After this you can use the Stop method of the animation to stop it.