im trying to figure out how to make it so that the animation only plays when the start to actually run instead of just standing still
What i have currently:
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Status = Character:WaitForChild("Status")
local SprintCheck = Character:WaitForChild("SprintCheck")
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Animator = Humanoid:WaitForChild("Animator")
local RunTrack = Animator:LoadAnimation(script:WaitForChild("RunAnim"))
UserInputService.InputBegan:Connect(function(Input,IsTyping)
if Input.KeyCode == Enum.KeyCode.LeftControl then
if SprintCheck.Value == true then
RunTrack:Stop()
SprintCheck.Value = false -- Gonna change this later to do it on server side
Humanoid.WalkSpeed = 16
print("NotSprinting")
elseif SprintCheck.Value == false then
RunTrack:Play()
SprintCheck.Value = true -- Gonna change this later to do it on server side
Humanoid.WalkSpeed = 24
print("Sprinting")
end
end
end)
I just changed a tiny bit of your code but this should work:
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAppearanceLoaded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Animator = Humanoid:FindFirstChildOfClass("Animator")
local RunTrack = Animator:LoadAnimation(script.RunAnim)
RunTrack.Looped = true
local IsRunning = false
UserInputService.InputBegan:Connect(function(Input,IsTyping)
if IsTyping then return end
if Input.KeyCode == Enum.KeyCode.LeftControl then
IsRunning = not IsRunning
if IsRunning then
RunTrack:Play()
Humanoid.WalkSpeed = 24
else
RunTrack:Stop()
Humanoid:ResetPropertyToDefault("WalkSpeed")
end
end
end)