I need this code to basically do the following: Have the function not running while I'm at a speed less than or equal to 49. Have the function run when my walk speed changes to more than or equal to 50. I have made the function already, and need someone to give me a loop that can detect if my speed has changed, and then output the function. Here's my code I have:
local sp = script.Parent.Parent.Character:FindFirstChild("Humanoid")
activate = 50
deactivate = 49
function trail()
wait(0.01)
local ft = Instance.new("Part")
ft.TopSurface = "Smooth"
ft.BottomSurface = "Smooth"
ft.Anchored = true
ft.FormFactor = "Custom"
ft.Size = Vector3.new(0.98, 1.98, 0.98)
ft.Transparency = 0.7
ft.Parent = game.workspace
ft.CanCollide = false
ft.BrickColor = BrickColor.new("Bright yellow")
ft.CFrame = CFrame.new(script.Parent.Parent.Character:FindFirstChild("Torso").Position.X,script.Parent.Parent.Character:FindFirstChild("Torso").Position.Y-0,script.Parent.Parent.Character:FindFirstChild("Torso").Position.Z)--Edited
game.Debris:AddItem(ft,0.8)
local fla = Instance.new("Part")
fla.TopSurface = "Smooth"
fla.BottomSurface = "Smooth"
fla.Anchored = true
fla.FormFactor = "Custom"
fla.Size = Vector3.new(0.98, 1.98, 0.98)
fla.Transparency = 0.7
fla.Parent = game.workspace
fla.CanCollide = false
fla.BrickColor = BrickColor.new("Bright yellow")
fla.CFrame = CFrame.new(script.Parent.Parent.Character:FindFirstChild("Left Arm").Position.X,script.Parent.Parent.Character:FindFirstChild("Left Arm").Position.Y-0,script.Parent.Parent.Character:FindFirstChild("Left Arm").Position.Z)--Edited
game.Debris:AddItem(fla,0.8)
local fra = Instance.new("Part")
fra.TopSurface = "Smooth"
fra.BottomSurface = "Smooth"
fra.Anchored = true
fra.FormFactor = "Custom"
fra.Size = Vector3.new(0.98, 1.98, 0.98)
fra.Transparency = 0.7
fra.Parent = game.workspace
fra.CanCollide = false
fra.BrickColor = BrickColor.new("Bright yellow")
fra.CFrame = CFrame.new(script.Parent.Parent.Character:FindFirstChild("Right Arm").Position.X,script.Parent.Parent.Character:FindFirstChild("Right Arm").Position.Y-0,script.Parent.Parent.Character:FindFirstChild("Right Arm").Position.Z)--Edited
game.Debris:AddItem(fra,0.8)
local fll = Instance.new("Part")
fll.TopSurface = "Smooth"
fll.BottomSurface = "Smooth"
fll.Anchored = true
fll.FormFactor = "Custom"
fll.Size = Vector3.new(0.98, 1.98, 0.98)
fll.Transparency = 0.7
fll.Parent = game.workspace
fll.CanCollide = false
fll.BrickColor = BrickColor.new("Bright yellow")
fll.CFrame = CFrame.new(script.Parent.Parent.Character:FindFirstChild("Left Leg").Position.X,script.Parent.Parent.Character:FindFirstChild("Left Leg").Position.Y-0,script.Parent.Parent.Character:FindFirstChild("Left Leg").Position.Z)--Edited
game.Debris:AddItem(fll,0.8)
local frl = Instance.new("Part")
frl.TopSurface = "Smooth"
frl.BottomSurface = "Smooth"
frl.Anchored = true
frl.FormFactor = "Custom"
frl.Size = Vector3.new(0.98, 1.98, 0.98)
frl.Transparency = 0.7
frl.Parent = game.workspace
frl.CanCollide = false
frl.BrickColor = BrickColor.new("Bright yellow")
frl.CFrame = CFrame.new(script.Parent.Parent.Character:FindFirstChild("Right Leg").Position.X,script.Parent.Parent.Character:FindFirstChild("Right Leg").Position.Y-0,script.Parent.Parent.Character:FindFirstChild("Right Leg").Position.Z)--Edited
game.Debris:AddItem(frl,0.8)
local fh = Instance.new("Part")
fh.TopSurface = "Smooth"
fh.BottomSurface = "Smooth"
fh.Anchored = true
fh.FormFactor = "Custom"
fh.Size = Vector3.new(0.98, 0.98, 0.98)
fh.Transparency = 0.7
fh.Parent = game.workspace
fh.CanCollide = false
fh.BrickColor = BrickColor.new("Bright yellow")
fh.CFrame = CFrame.new(script.Parent.Parent.Character:FindFirstChild("Head").Position.X,script.Parent.Parent.Character:FindFirstChild("Head").Position.Y-0,script.Parent.Parent.Character:FindFirstChild("Head").Position.Z)--Edited
game.Debris:AddItem(fh,0.8)
end
while sp.WalkSpeed >= activate do
repeat
trail()
until sp.WalkSpeed <= deactivate
end
The function basically creates a trail that will follow the player. The script is in the starterpack, and works without all the loops and stuff. When the player reaches the walk speed of 50 or above, I want the function to be repeated, but for some reason it won't work. When the player has come back down from the walk speed of 50 or above, and goes below or equal to 49, I need the repeat to stop, and then clear all the debris with it.

1 comment
Ok i'll test this out, thanks.