Ok so, I just made a script where when a player walks, a certain animation using Lerp() is played, and a separate one when a player stops. I have tried using Humanoid:GetState() but it just keeps playing the animation, even after the player has stopped moving.

Code:

--LocalScript

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local UserInputService = game:GetService('UserInputService')

local RequestType1 = ReplicatedStorage:WaitForChild('RequestType1')

local AnimationRequestType0, AnimationRequestType1, AnimationRequestType2 = ReplicatedStorage:WaitForChild('AnimationRequestType0'), ReplicatedStorage:WaitForChild('AnimationRequestType1'), ReplicatedStorage:WaitForChild('AnimationRequestType2')

local Players = game:GetService('Players')

local Player = Players.LocalPlayer

repeat
	
	wait()
	
until Player.Character

local RequestType = 0

local Moving = false

local Fired = false

local RequestType1KeyCode = Enum.KeyCode.Insert

local AnimationRequestType1KeyCode = Enum.KeyCode.W

local function FireServerInput(Input, gameProcessed)
	
	print(Input.KeyCode)
	
	if Input.KeyCode == RequestType1KeyCode then
		
		RequestType1:FireServer(Player)
		
		Fired = true
		
		RequestType = 1
		
	elseif RequestType == 1 and Fired and Player.Character.Humanoid:GetState() == Enum.HumanoidStateType.RunningNoPhysics and Player.Character.Humanoid.Running then
		
		if Input.KeyCode == AnimationRequestType1KeyCode and Player.Character.Humanoid.WalkSpeed > 0 then
			
			print(Input.KeyCode)
		
			AnimationRequestType1:FireServer()
			
			Moving = true
			
		end
			
	end
	
	if Moving and Player.Character.Humanoid:GetState() == Enum.HumanoidStateType.PlatformStanding then
			
		AnimationRequestType0:FireServer()
			
		Moving = false
			
	end
		
end

UserInputService.InputBegan:Connect(FireServerInput)

I am not really that skilled with Humanoid States, so if there's any state, or any event for when a player's character is standing still, please let me know along with whatever is wrong with my code. Thank you.

2 comments

0

PlatformStanding isn't the state where a humanoid is not moving, currently there isn't one that I know of. A loop should do the trick

0

~@GoldenAngelInDisguise What KIND of loop? I don't see the possibility of any type of loop helping me in the slightest. Please give a more detailed answer.