Run script not playing when player stopped jumping

hello all, my run script works perfectly fine it’s that it will not continue playing when the player stops jumping.

Example

ik the source code is rlly messy

local uis = game:GetService("UserInputService")
local cameraShake = require(game.ReplicatedStorage.CameraShaker)
local vibrationPreset = cameraShake.Presets.Vibration
local TweenService = game:GetService("TweenService")
local run = TweenService:Create(workspace.CurrentCamera, TweenInfo.new(0.5), {FieldOfView = 75})
local walk = TweenService:Create(workspace.CurrentCamera, TweenInfo.new(0.5), {FieldOfView = 70})
local playersHumanoid = game.Players.LocalPlayer.Character.Humanoid
local newAnimation = Instance.new("Animation")
newAnimation.AnimationId = "rbxassetid://"..script:GetAttribute("AnimationID")
loadAnimation = playersHumanoid:LoadAnimation(newAnimation)
local runSpeed = 25
local walkSpeed = 16
local contextService = game:GetService("ContextActionService")


uis.InputBegan:Connect(function(Key)
	if Key.KeyCode == Enum.KeyCode.LeftShift then
			run:Play()
			loadAnimation:Play()
			playersHumanoid.WalkSpeed = runSpeed
	end
end)

uis.InputEnded:Connect(function(Key)
	if Key.KeyCode == Enum.KeyCode.LeftShift then
		walk:Play()
		loadAnimation:Stop()
		playersHumanoid.WalkSpeed = walkSpeed
	end
end)

playersHumanoid.Changed:Connect(function()
	if playersHumanoid.Jump and loadAnimation.IsPlaying then
		loadAnimation:Stop()
	end
end)

Connect a function up to Humanoid.StateType.Landed.

In that function check if they’re running, if they are, turn on the runAnimation. :slight_smile:

Will this continue it while I’m still holding down the input or keep on going when I landed WITHOUT holding it?

nevermind. just read the whole sentence lol.

Humanoid.StateType? it keeps on erroring when i put that

https://developer.roblox.com/en-us/api-reference/event/Humanoid/StateChanged

So for your example it would be.

playersHumanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Landed and PlayerIsRunning then -- make a true/false variable, for when the player is running or not running)
	-- Load running animation
	end

end)

Thanks! it Works. :smile:

  • 30 thing dont mind this