local UIS = game:GetService("UserInputService")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local RunAnim = Instance.new("Animation")
RunAnim.AnimationId = "rbxassetid://9530567165"
local animationTrack = script.Parent:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(RunAnim)
local fallAnim = Instance.new("Animation")
fallAnim.AnimationId = "rbxassetid://9535536699"
local fallAnimTrack = script.Parent:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(fallAnim)
UIS.InputBegan:Connect(function(input, gameProcessed) -- starts sprinting
if not gameProcessed then
Humanoid.Running:Connect(function(speed)
if speed ~= 0 and input.KeyCode == Enum.KeyCode.LeftShift then
if not Humanoid.FreeFalling then
Humanoid.WalkSpeed = 25
animationTrack:Play()
end
else
if Humanoid.FreeFalling then
animationTrack:Stop()
end
end
end)
end
end)
UIS.InputEnded:Connect(function(input, gameProcessed) -- no longer starts sprinting
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.LeftShift then
Humanoid.WalkSpeed = 16
animationTrack:Stop()
end
end
end)
local UIS = game:GetService("UserInputService")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local RunAnim = Instance.new("Animation")
RunAnim.AnimationId = "rbxassetid://9530567165"
local animationTrack = script.Parent:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(RunAnim)
local fallAnim = Instance.new("Animation")
fallAnim.AnimationId = "rbxassetid://9535536699"
local fallAnimTrack = script.Parent:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(fallAnim)
UIS.InputBegan:Connect(function(input, gameProcessed) -- starts sprinting
if not gameProcessed then
if speed ~= 0 and input.KeyCode == Enum.KeyCode.LeftShift then
if not Humanoid.FreeFalling then
Humanoid.WalkSpeed = 25
animationTrack:Play()
end
else
if Humanoid.FreeFalling then
animationTrack:Stop()
end
end
end
end)
UIS.InputEnded:Connect(function(input, gameProcessed) -- no longer starts sprinting
if not gameProcessed then
if input.KeyCode == Enum.KeyCode.LeftShift then
Humanoid.WalkSpeed = 16
animationTrack:Stop()
end
end
end)
when you’re loading the animations when you’ve already referenced the Humanoid? Also don’t use the Humanoid.Running event inside of here, however, if you HAVE to then consider making a variable which detects if you pressed a key or not i.e.
local HoldingLeftShit = UIS:IsKeyDown(Enum.KeyCode.LeftShift)
And reference it when the humanoid starts running like;
Humanoid.Running:Connect(function(speed)
if UIS:IsKeyDown(Enum.KeyCode.LeftShift then
-- do stuff
else
-- dont do stuff
end
end)
or just use a regular UIS.InputBegan script which detects when you’re holding down shift and increases your speed and UIS.InputEnded which @SharkBloxYT above already did
local UIS = game:GetService("UserInputService")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local RunAnim = Instance.new("Animation")
RunAnim.AnimationId = "rbxassetid://9530567165"
local animationTrack = script.Parent:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(RunAnim)
local fallAnim = Instance.new("Animation")
fallAnim.AnimationId = "rbxassetid://9535536699"
local fallAnimTrack = script.Parent:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(fallAnim)
UIS.InputBegan:Connect(function(input, gameProcessed) -- starts sprinting
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
if speed ~= 0 then
if not Humanoid.FreeFalling then
Humanoid.WalkSpeed = 25
animationTrack:Play()
end
else
if Humanoid.FreeFalling then
animationTrack:Stop()
end
end
end
end
end)
UIS.InputEnded:Connect(function(input2, gameProcessed2) -- no longer starts sprinting
Humanoid.WalkSpeed = 16
animationTrack:Stop()
end)
Whenever the player presses a key then it will detect if it is LeftShift and then the player should sprint.