Particle.Enabled not changing

I made this script which checks if the player is running, and if he is the particleEmitter is enabled else
its false

local hum:Humanoid = script.Parent.Humanoid
local walk = script.Parent.HumanoidRootPart.WalkParticle.Walk


hum.StateChanged:Connect(function(old,new)
	if new == Enum.HumanoidStateType.Running then
		walk.Enabled = true
		print("running")
	else
		walk.Enabled = false
	end	
end)

nothing in output btw. its not settings to false

try adding a print in else
and another print once function is triggered

hum.StateChanged:Connect(function(old,new)
   print("state changed")
	if new == Enum.HumanoidStateType.Running then
		walk.Enabled = true
		print("running")
	else
		walk.Enabled = false
       print("not running")
	end	
end)

this will help you understand more of what’s going on

You can just use Humanoid.Running which will fire if the player is running.

Humanoid.Running:Connect(function()
    ...
end)

Edit: Second example that uses Humanoid.Running:

local function onRunning(speed)
	if speed > 0 then
		print("Player is running")
	else
		print("Player has stopped")
	end
end

workspace.Player.Humanoid.Running:Connect(onRunning)

There’s another running type called RunningNoPhysics
Not quite sure why it exists, but you can just do

if new == Enum.HumanoidStateType.Running or new == Enum.HumanoidStateType.RunningNoPhysics then

If you wanna save some time and not type the if statement all over again, you can put them in a table and use table.find

local RunningTypes = {
	Enum.HumanoidStateType.Running,
	Enum.HumanoidStateType.RunningNoPhysics
}

if table.find(RunningTypes,new) then

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.