Hello everyone, i make sprint function and uhm i have problem
When i press Shift (when standing), my character running (using animation and +speed boost), yeah when i not pressing Shift character don’t starting animation run and not speed boost
I need that when the player pinches the shift in PLACE, he does not play the running animation, and when he starts walking, then you can play the animation, but while running, if the player stops, it is necessary that his speed and animation reset
here code
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Char = Player.Character
local hum = Char:FindFirstChildOfClass("Humanoid")
local RepStorage = game:GetService("ReplicatedStorage")
local IsRunning = false
local isJumping = false
local walkSpeed = hum.WalkSpeed -- Скорость ходьбы по умолчанию
local jumppower = hum.JumpPower
local runSpeed = 24 -- Скорость бега
local jumpPower = 0
local runAnim = RepStorage.Animations.RunAnim
local runAnimationTrack = hum:LoadAnimation(runAnim)
hum.UseJumpPower = true
local function ShiftPressed()
if hum:GetState() == Enum.HumanoidStateType.Jumping or hum:GetState() == Enum.HumanoidStateType.Freefall then
isJumping = true
end
if IsRunning and not isJumping then
hum.WalkSpeed = walkSpeed
runAnimationTrack:Stop()
IsRunning = false
elseif not isJumping then
hum.WalkSpeed = runSpeed
runAnimationTrack:Play()
IsRunning = true
hum.Running:Connect(function(speed)
if speed <= 0 then
runAnimationTrack:Stop()
hum.WalkSpeed = walkSpeed
IsRunning = false
end
end)
end
end
local function handleShiftReleased()
isJumping = false
if IsRunning then
hum.WalkSpeed = walkSpeed
runAnimationTrack:Stop()
IsRunning = false
end
end
UserInputService.InputBegan:Connect(function(input, _gameProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift and not _gameProcessed then
ShiftPressed()
hum.JumpPower = jumpPower
end
end)
UserInputService.InputEnded:Connect(function(input, _gameProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift and not _gameProcessed then
handleShiftReleased()
hum.JumpPower = jumppower
end
end)