How can I make a partcle play only when the player is walking

I’m making a platformer and I want a particle that only plays when there walking and not when there standing still how would I make this?

You can check the Humanoid MoveDirection property

local humanoid:Humanoid = char:FindFirstChild("Humanoid")
if not humanoid then return end

local particle = Instance.new("ParticleEmitter",char.HumanoidRootPart)
particle.Enabled = false

game:GetService("RunService").RenderStepped:Connect(function()
	if humanoid.MoveDirection ~= Vector3.zero then
		local stat = humanoid:GetState()
		if stat == Enum.HumanoidStateType.Running then
			particle.Enabled = true
		else
			particle.Enabled = false
		end
	else
		particle.Enabled = false
	end
end)
1 Like

were should I put the script?
and also could it be were it just puts a particle I made into the humanoid

It would have to be in a LocalScript inside of StarterCharacterScripts, and you would have to modify it to:

local char = script.Parent
local humanoid:Humanoid = char:FindFirstChild("Humanoid")
if not humanoid then return end

local particle = Instance.new("ParticleEmitter",char.HumanoidRootPart)
particle.Enabled = false

game:GetService("RunService").RenderStepped:Connect(function()
	if humanoid.MoveDirection ~= Vector3.zero then
		local stat = humanoid:GetState()
		if stat == Enum.HumanoidStateType.Running then
			particle.Enabled = true
		else
			particle.Enabled = false
		end
	else
		particle.Enabled = false
	end
end)

Also, the particle is already being made inside the character.

1 Like

You could copy from the script above or you can do this

Server Version (If you want to call the particles on the server) (NOT RECOMMENDED) (ServerScriptService)

-- // Declarations

local players = game:GetService('Players')

-- // Connections

players.PlayerAdded:Connect(function(player) -- Roblox PlayerAdded function, when a new player joins; this fires.
	local newConnection = player.CharacterAppearanceLoaded:Connect(function(characterModel) -- feel free to add a disconnect when you die
		local particle = InsertParticlePathHere or Instance.new('ParticleEmitter', characterModel.HumanoidRootPart) -- Change the path or leave it
		particle.Enabled = false -- Disable starting Enabled
		characterModel.Humanoid:GetPropertyChangedSignal('MoveDirection'):Connect(function() -- This is better than running a renderstep
			if (characterModel.Humanoid.MoveDirection).Magnitude > 0 then -- Am I actually moving?
				particle.Enabled = true -- Show particles
			else -- Not moving
				particle.Enabled = false -- Hide particles
			end
		end)
	end)
end)

Client: (StarterCharacterScript)

-- Init
repeat task.wait() until game:IsLoaded() -- not really needed
-- // Declarations

local players 		 = game:GetService('Players')
local localPlayer 	 = players.LocalPlayer
local characterModel = localPlayer.Character

repeat task.wait() until characterModel:FindFirstChild('Humanoid') and characterModel:FindFirstChild('HumanoidRootPart') -- Loaded?

local particle 		 = InsertParticlePathHere or Instance.new('ParticleEmitter', characterModel.HumanoidRootPart) -- Change the path or leave it

characterModel.Humanoid.Changed:Connect(function(property) -- propertChangedSignal or Changed
	if property == 'MoveDirection' then
		if (characterModel.Humanoid.MoveDirection).Magnitude > 0 then -- Am I actually moving?
			particle.Enabled = true -- Show particles
		else -- Not moving
			particle.Enabled = false -- Hide particles
		end
	end
end)

or

Client: (StarterCharacterScript)

-- // Declarations

local players 		 = game:GetService('Players')
local localPlayer 	 = players.LocalPlayer
repeat task.wait() until game:IsLoaded() and localPlayer.Character -- not really needed
local characterModel = localPlayer.Character
repeat task.wait() until characterModel:FindFirstChild('Humanoid') and characterModel:FindFirstChild('HumanoidRootPart')

-- Cringy main

local newParticle = InsertParticlePath or Instance.new('ParticleEmitter', characterModel.HumanoidRootPart)
newParticle.Enabled = false
characterModel.Humanoid:GetPropertyChangedSignal('MoveDirection'):Connect(function()
	if (characterModel.Humanoid.MoveDirection).Magnitude > 0 then
		newParticle.Enabled = true
	else
		newParticle.Enabled = false
	end
end)
1 Like