Hey everyone! So recently I made a script that enables particles in your feet when you walk on specific materials, It works well so far but I had one small Issue. The particles don’t get disabled when I stop moving and I wanted to know how I can fix that.
Here’s the script
local humanoid = script.Parent:FindFirstChild("Humanoid")
local HumanoidRootPart = script.Parent.HumanoidRootPart
humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
if humanoid.FloorMaterial == Enum.Material.Snow then
script.Parent.LeftFoot.ParticlePart.Enabled = true
script.Parent.RightFoot.ParticlePart.Enabled = true
elseif humanoid.FloorMaterial == Enum.Material.Grass then
script.Parent.LeftFoot.ParticlePart.Enabled = false
script.Parent.RightFoot.ParticlePart.Enabled = false
end
end)
I’m new to scripting and I would love if you guide me to what exactly I should do or replace since I’ve had this issue for a really long time and there isn’t any video explaining it so I figured I should put it here so it’s more specific!
local humanoid = script.Parent:FindFirstChild("Humanoid")
local leftFoot = script.Parent.LeftFoot
local rightFoot = script.Parent.RightFoot
game:GetService("RunService").Stepped:Connect(function()
if humanoid.MoveDirection.Magnitude > 0 then
if humanoid.FloorMaterial == Enum.Material.Snow then
script.Parent.RightFoot.ParticlePart.Enabled = true;
script.Parent.LeftFoot.ParticlePart.Enabled = true;
end
else
for _, emitter in pairs (leftFoot) do
if emitter:IsA("ParticleEmitter") then
emitter.Enabled = false;
end
end
for _, emitter in pairs (rightFoot) do
if emitter:IsA("ParticleEmitter") then
emitter.Enabled = false;
end
end
end
end)
In the for loops leftFoot and rightFoot should have :GetChildren() on the end, that was my mistake in the image I sent. Just to make things easier for you, here’s a working example (not material specific though that should be easy to adjust), you can build it from here. Copy this in a script and put it in the ServerScriptService.
local players = game:GetService("Players");
local run = game:GetService("RunService");
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid");
local leftFoot, rightFoot = character:WaitForChild("LeftFoot"), character:WaitForChild("RightFoot")
local leftEmitter, rightEmitter = Instance.new("ParticleEmitter", leftFoot), Instance.new("ParticleEmitter", rightFoot)
leftEmitter.Enabled, rightEmitter.Enabled = false, false;
run.Stepped:Connect(function(delta)
if humanoid.MoveDirection.Magnitude > 0 then
if not leftEmitter.Enabled and not rightEmitter.Enabled then
leftEmitter.Enabled, rightEmitter.Enabled = true, true
end
else
if leftEmitter.Enabled and rightEmitter.Enabled then
leftEmitter.Enabled, rightEmitter.Enabled = false, false
end
end
end)
end)
end)
It works but now it doesn’t stop when the material changes
local players = game:GetService("Players");
local run = game:GetService("RunService");
local humanoid = script.Parent:WaitForChild("Humanoid");
local leftFoot, rightFoot = script.Parent:WaitForChild("LeftFoot"), script.Parent:WaitForChild("RightFoot")
local leftEmitter, rightEmitter = leftFoot.ParticlePart, rightFoot.ParticlePart
leftEmitter.Enabled, rightEmitter.Enabled = false, false;
run.Stepped:Connect(function(delta)
if humanoid.MoveDirection.Magnitude > 0 then
if not leftEmitter.Enabled and not rightEmitter.Enabled then
leftEmitter.Enabled, rightEmitter.Enabled = true, true
end
else
if leftEmitter.Enabled and rightEmitter.Enabled then
leftEmitter.Enabled, rightEmitter.Enabled = false, false
end
end
end)
humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
if humanoid.FloorMaterial == Enum.Material.Snow then
leftEmitter.Enabled = true
rightEmitter.Enabled = true
elseif humanoid.FloorMaterial == Enum.Material.Grass then
leftEmitter.Enabled = false
rightEmitter.Enabled = false
end
end)
local players = game:GetService("Players");
local run = game:GetService("RunService");
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid");
local leftFoot, rightFoot = character:WaitForChild("LeftFoot"), character:WaitForChild("RightFoot")
local leftGrassParticle, rightGrassParticle = Instance.new("ParticleEmitter", leftFoot), Instance.new("ParticleEmitter", rightFoot)
leftGrassParticle.Color, rightGrassParticle.Color = ColorSequence.new(Color3.fromRGB(0, 255, 0), Color3.fromRGB(0, 255, 0)), ColorSequence.new(Color3.fromRGB(0, 255, 0), Color3.fromRGB(0, 255, 0))
local leftSnowParticle, rightSnowParticle = Instance.new("ParticleEmitter", leftFoot), Instance.new("ParticleEmitter", rightFoot)
local function disableAllParticles ()
for _, particle in pairs(leftFoot:GetChildren()) do
if particle:IsA("ParticleEmitter") then
particle.Enabled = false;
end
end
for _, particle in pairs(rightFoot:GetChildren()) do
if particle:IsA("ParticleEmitter") then
particle.Enabled = false;
end
end
end
run.Stepped:Connect(function(delta)
if humanoid.MoveDirection.Magnitude > 0 then
-- grass
if humanoid.FloorMaterial == Enum.Material.Grass then
leftGrassParticle.Enabled, rightGrassParticle.Enabled = true, true
else
leftGrassParticle.Enabled, rightGrassParticle.Enabled = false, false
end
-- snow
if humanoid.FloorMaterial == Enum.Material.Snow then
leftSnowParticle.Enabled, rightSnowParticle.Enabled = true, true
else
leftSnowParticle.Enabled, rightSnowParticle.Enabled = false, false
end
else
disableAllParticles();
end
end)
end)
end)