Trying to detect when humanoid is not touching the ground fails

I am currently working with a particle emitter, whenever the player starts running he will leave smoke particles behind him:

image

I just want the smoke to dissappear if the humanoid is not moving (already achieved that) or if he is not touching the ground (what i still want to achieve)

So this is my script:

local humanoid = script.Parent:WaitForChild("Humanoid")

local emitter = Instance.new("ParticleEmitter")
	emitter.Name = "WalkFX"
	emitter.Texture = "http://www.roblox.com/asset/?id=378834872"
	local invisible = {
	 NumberSequenceKeypoint.new(0,1);
	 NumberSequenceKeypoint.new(1,1);
	}

	local attach = Instance.new("Attachment")
	attach.Parent = script.Parent:WaitForChild("Torso")
	attach.Position = Vector3.new(0,-3,0)
	emitter.Parent = attach
	emitter.Transparency = NumberSequence.new(invisible)
	emitter.Rate = 0
	
	local function Speed1()
		local Transparency = {
	NumberSequenceKeypoint.new(0, 0);
	NumberSequenceKeypoint.new(0.227, 0);
	NumberSequenceKeypoint.new(0.704, 1);
	NumberSequenceKeypoint.new(1, 1);
	}
	
	local Size = {
	NumberSequenceKeypoint.new(0,0);
	NumberSequenceKeypoint.new(0.2,1.13);
	NumberSequenceKeypoint.new(0.494,0);
	NumberSequenceKeypoint.new(1,0);
	}
	
	emitter.Transparency = NumberSequence.new(Transparency)
	emitter.Size = NumberSequence.new(Size)
	emitter.Lifetime = NumberRange.new(1,2)
	emitter.Rate = 3
	emitter.RotSpeed = NumberRange.new(20)
	emitter.Speed = NumberRange.new(2.5)
		
	end
	
	local function Speed2()
		local Transparency = {
	NumberSequenceKeypoint.new(0, 0);
	NumberSequenceKeypoint.new(0.227, 0);
	NumberSequenceKeypoint.new(0.704, 1);
	NumberSequenceKeypoint.new(1, 1);
	}
	
	local Size = {
	NumberSequenceKeypoint.new(0,0);
	NumberSequenceKeypoint.new(0.2,1.75);
	NumberSequenceKeypoint.new(0.494,0);
	NumberSequenceKeypoint.new(1,0);
	}
	
	emitter.Transparency = NumberSequence.new(Transparency)
	emitter.Size = NumberSequence.new(Size)
	emitter.Lifetime = NumberRange.new(1,2)
	emitter.Rate = 5
	emitter.RotSpeed = NumberRange.new(20)
	emitter.Speed = NumberRange.new(2.5)
	end
	
	local function Speed3()
		local Transparency = {
	NumberSequenceKeypoint.new(0, 0);
	NumberSequenceKeypoint.new(0.227, 0);
	NumberSequenceKeypoint.new(0.704, 1);
	NumberSequenceKeypoint.new(1, 1);
	}
	
	local Size = {
	NumberSequenceKeypoint.new(0,0);
	NumberSequenceKeypoint.new(0.2,2.75);
	NumberSequenceKeypoint.new(0.494,0);
	NumberSequenceKeypoint.new(1,0);
	}
	
	emitter.Transparency = NumberSequence.new(Transparency)
	emitter.Size = NumberSequence.new(Size)
	emitter.Lifetime = NumberRange.new(1,2)
	emitter.Rate = 7
	emitter.RotSpeed = NumberRange.new(20)
	emitter.Speed = NumberRange.new(2.5)
	end
	
	local function Speed4()
		local Transparency = {
	NumberSequenceKeypoint.new(0, 0);
	NumberSequenceKeypoint.new(0.227, 0);
	NumberSequenceKeypoint.new(0.704, 1);
	NumberSequenceKeypoint.new(1, 1);
	}
	
	local Size = {
	NumberSequenceKeypoint.new(0,0);
	NumberSequenceKeypoint.new(0.2,1);
	NumberSequenceKeypoint.new(0.494,0);
	NumberSequenceKeypoint.new(1,0);
	}
	
	emitter.Transparency = NumberSequence.new(Transparency)
	emitter.Size = NumberSequence.new(Size)
	emitter.Lifetime = NumberRange.new(1,2)
	emitter.Rate = 2
	emitter.RotSpeed = NumberRange.new(20)
	emitter.Speed = NumberRange.new(2.5)
	end
	
while true do
	if humanoid.WalkSpeed > 20 and humanoid.WalkSpeed < 30 and not humanoid.FloorMaterial ~= Enum.Material.Air then
		Speed1()
	elseif humanoid.WalkSpeed > 30 and humanoid.WalkSpeed <= 40 and not humanoid.FloorMaterial ~= Enum.Material.Air then
        Speed2()
	elseif humanoid.WalkSpeed > 40 and not humanoid.FloorMaterial ~= Enum.Material.Air then
		Speed3()
	elseif humanoid.WalkSpeed < 20 and humanoid.WalkSpeed > 16 and humanoid.FloorMaterial ~= Enum.Material.Air then
		Speed4()
	elseif humanoid.WalkSpeed <= 16 or humanoid.FloorMaterial == Enum.Material.Air then
		emitter.Rate = 0
		print("Invisible")
	end
	wait(0.1)
end

I already tried googling around and using Humanoid.FloorMaterial ~= nil or Humanoid:GetState but nothing seems to work and nothing appears on the output either

Perhaps you could add multiple checks instead of one. I’ll show you 3 checks you could use:

local RS    = game:GetService("RunService").RenderStepped
local Humanoid  = script.Parent:WaitForChild("Humanoid")

Humanoid.StateChanged:Connect(function(oldState, newState)
    if (newState == Enum.HumanoidStateType.Freefall) then
        emitter.Rate = 0
        print("Invisible")
    end
end)

Humanoid.FreeFalling:Connect(function()
    emitter.Rate = 0
    print("Invisible")
end)

RS:Connect(function()
    if (Humanoid.FloorMaterial == nil or Humanoid.FloorMaterial == Enum.Material.Air) then
        emitter.Rate = 0
    end
end)
5 Likes

Thank you, i didn’t know you could do it these ways.

The more efficient option (and the only one that worked) was the first one.

The second one didn’t give me any results (maybe because i used it wrong?)

The third one was only for localscripts and i am using a server script.

Again, thank you for your help

1 Like

Never use RenderStepped if you aren’t updating something that needs to occur before a frame renders (such as updating the camera or a part of the character like their transparency). Use Heartbeat for all intents and purposes related to RunService. Stepped if you need to update before physics simulation.

1 Like