Disable inserted trails inside the player under 50 speed

How About This?

local LP = game:GetService("Players").LocalPlayer
local Character = LP.Character
local Humanoid = Character:FindFirstChildOfClass("Humanoid")

local Check = function()
	if Humanoid.WalkSpeed > 50 then
		Character.Head:FindFirstChild("Trail").Enabled = true
		
	elseif Humanoid.WalkSpeed < 50 then
		if Character.Head:FindFirstChild("Trail") then
			Character.Head:FindFirstChild("Trail").Enabled = false
		end
	end
end

while task.wait(0.25) do
	Check()
end


hey, this didnt work for me, i dont think the script is broken but i think it just doesnt enable the trails.

output:
image

this is another script in startercharacterscripts, deleting it doesnt work but i think firing the remoteevent is important which we left out

local player = game.Players.LocalPlayer
local character = player.Character or script.Parent
local humanoid = character.Humanoid
local remoteevent = game.ReplicatedStorage.RemoteEvent

if humanoid.WalkSpeed == 60 then
	remoteevent:FireServer()
end

this is the remoteevent script, located in serverscriptservice:

local remoteevent = game.ReplicatedStorage.RemoteEvent
local trail = game.ServerStorage.Trail
local particle = game.ServerStorage.ParticleEmitter

remoteevent.OnServerEvent:Connect(function(player)
	local character = player.Character

	-- Trail 1
	local trail1 = trail:Clone()
	trail1.Parent = character
	local attachment0 = Instance.new("Attachment", character.Head)
	attachment0.Name = "TrailAttachment0"
	local attachment1 = Instance.new("Attachment", character.UpperTorso)
	attachment1.Name = "TrailAttachment1"

	trail1.Attachment0 = attachment0
	trail1.Attachment1 = attachment1

	-- Trail 2
	local trail2 = trail:Clone()
	trail2.Parent = character
	local attachment2 = Instance.new("Attachment", character.RightUpperArm)
	attachment2.Name = "TrailAttachment2"
	local attachment3 = Instance.new("Attachment", character.RightLowerArm)
	attachment3.Name = "TrailAttachment3"

	trail2.Attachment0 = attachment2
	trail2.Attachment1 = attachment3

	-- Trail 3
	local trail3 = trail:Clone()
	trail3.Parent = character
	local attachment4 = Instance.new("Attachment", character.RightLowerArm)
	attachment2.Name = "TrailAttachment4"
	local attachment5 = Instance.new("Attachment", character.RightHand)
	attachment3.Name = "TrailAttachment5"

	trail3.Attachment0 = attachment4
	trail3.Attachment1 = attachment5

	-- Trail 4
	local trail4 = trail:Clone()
	trail4.Parent = character
	local attachment6 = Instance.new("Attachment", character.LeftUpperArm)
	attachment6.Name = "TrailAttachment4"
	local attachment7 = Instance.new("Attachment", character.LeftLowerArm)
	attachment7.Name = "TrailAttachment5"

	trail4.Attachment0 = attachment6
	trail4.Attachment1 = attachment7

	-- Trail 5
	local trail5 = trail:Clone()
	trail5.Parent = character
	local attachment8 = Instance.new("Attachment", character.LeftLowerArm)
	attachment6.Name = "TrailAttachment4"
	local attachment9 = Instance.new("Attachment", character.LeftHand)
	attachment7.Name = "TrailAttachment5"

	trail5.Attachment0 = attachment8
	trail5.Attachment1 = attachment9
	
	-- Trail 6
	local trail6 = trail:Clone()
	trail6.Parent = character
	local attachment10 = Instance.new("Attachment", character.LowerTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment11 = Instance.new("Attachment", character.UpperTorso)
	attachment7.Name = "TrailAttachment5"

	trail6.Attachment0 = attachment10
	trail6.Attachment1 = attachment11
	
	-- Trail 7
	local trail7 = trail:Clone()
	trail7.Parent = character
	local attachment12 = Instance.new("Attachment", character.UpperTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment13 = Instance.new("Attachment", character.RightUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail7.Attachment0 = attachment12
	trail7.Attachment1 = attachment13
	
	-- Trail 8
	local trail8 = trail:Clone()
	trail8.Parent = character
	local attachment14 = Instance.new("Attachment", character.UpperTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment15 = Instance.new("Attachment", character.LeftUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail8.Attachment0 = attachment14
	trail8.Attachment1 = attachment15
	
	-- Trail 9
	local trail9 = trail:Clone()
	trail9.Parent = character
	local attachment16 = Instance.new("Attachment", character.LeftUpperLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment17 = Instance.new("Attachment", character.LeftLowerLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail9.Attachment0 = attachment16
	trail9.Attachment1 = attachment17
	
	-- Trail 10
	local trail10 = trail:Clone()
	trail10.Parent = character
	local attachment18 = Instance.new("Attachment", character.LeftLowerLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment19 = Instance.new("Attachment", character.LeftFoot
	)
	attachment7.Name = "TrailAttachment5"

	trail10.Attachment0 = attachment18
	trail10.Attachment1 = attachment19
	
	-- Trail 11
	local trail11 = trail:Clone()
	trail11.Parent = character
	local attachment20 = Instance.new("Attachment", character.RightUpperLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment21 = Instance.new("Attachment", character.RightLowerLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail11.Attachment0 = attachment20
	trail11.Attachment1 = attachment21
	
	-- Trail 12
	local trail12 = trail:Clone()
	trail12.Parent = character
	local attachment22 = Instance.new("Attachment", character.RightLowerLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment23 = Instance.new("Attachment", character.RightFoot
	)
	attachment7.Name = "TrailAttachment5"

	trail12.Attachment0 = attachment22
	trail12.Attachment1 = attachment23
	
	-- Trail 13
	local trail13 = trail:Clone()
	trail13.Parent = character
	local attachment24 = Instance.new("Attachment", character.LeftHand)
	attachment6.Name = "TrailAttachment4"
	local attachment25 = Instance.new("Attachment", character.LeftUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail13.Attachment0 = attachment24
	trail13.Attachment1 = attachment25
	
	-- Trail 14
	local trail14 = trail:Clone()
	trail14.Parent = character
	local attachment26 = Instance.new("Attachment", character.RightHand)
	attachment6.Name = "TrailAttachment4"
	local attachment27 = Instance.new("Attachment", character.RightUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail14.Attachment0 = attachment26
	trail14.Attachment1 = attachment27
	
	-- Trail 15
	local trail15 = trail:Clone()
	trail15.Parent = character
	local attachment28 = Instance.new("Attachment", character.RightFoot)
	attachment6.Name = "TrailAttachment4"
	local attachment29 = Instance.new("Attachment", character.RightUpperLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail15.Attachment0 = attachment28
	trail15.Attachment1 = attachment29
	
	-- Trail 16
	local trail16 = trail:Clone()
	trail16.Parent = character
	local attachment30 = Instance.new("Attachment", character.LeftFoot)
	attachment6.Name = "TrailAttachment4"
	local attachment31 = Instance.new("Attachment", character.LeftUpperLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail16.Attachment0 = attachment30
	trail16.Attachment1 = attachment31
	
	-- Trail 17
	local trail17 = trail:Clone()
	trail17.Parent = character
	local attachment32 = Instance.new("Attachment", character.UpperTorso
	)
	attachment6.Name = "TrailAttachment4"
	local attachment33 = Instance.new("Attachment", character.RootPart
	)
	attachment7.Name = "TrailAttachment5"

	trail17.Attachment0 = attachment32
	trail17.Attachment1 = attachment33
	
	local particle2 = particle:Clone()
	particle2.Enabled = true
	particle2.Parent = character.UpperTorso
	
	local particle3 = particle:Clone()
	particle3.Enabled = true
	particle3.Parent = character.LowerTorso
	
	local particle4 = particle:Clone()
	particle4.Enabled = true
	particle4.Parent = character.LeftFoot
	
	local particle5 = particle:Clone()
	particle5.Enabled = true
	particle5.Parent = character.LeftLowerLeg
	
	local particle6 = particle:Clone()
	particle6.Enabled = true
	particle6.Parent = character.LeftUpperLeg
	
	
	local particle7 = particle:Clone()
	particle7.Enabled = true
	particle7.Parent = character.RightFoot
	
	local particle8 = particle:Clone()
	particle8.Enabled = true
	particle8.Parent = character.RightLowerLeg
	
	local particle9 = particle:Clone()
	particle9.Enabled = true
	particle9.Parent = character.RightUpperLeg
	
	local particle10 = particle:Clone()
	particle10.Enabled = true
	particle10.Parent = character.LeftHand
	
	local particle11 = particle:Clone()
	particle11.Enabled = true
	particle11.Parent = character.LeftLowerArm
	
	local particle12 = particle:Clone()
	particle12.Enabled = true
	particle12.Parent = character.LeftUpperArm
	
	local particle13 = particle:Clone()
	particle13.Enabled = true
	particle13.Parent = character.RightHand
	
	local particle14 = particle:Clone()
	particle14.Enabled = true
	particle14.Parent = character.RightLowerArm
	
	local particle15 = particle:Clone()
	particle15.Enabled = true
	particle15.Parent = character.RightUpperArm

end)

lastly, probably unimportant, is the script which speeds me up. its probably unnecesary but im posting it just in case its important.

	local player = game.Players.LocalPlayer
	local char = player.Character
	local hum = char.Humanoid
	local UserInputService = game:GetService("UserInputService")
	local speed = game.ReplicatedStorage.Speed.Value


	UserInputService.InputBegan:Connect(function(input, isTyping)
		if isTyping then return end
		if input.KeyCode == Enum.KeyCode.LeftShift then
			speed = true

			while speed == true do
				if hum.WalkSpeed == 250 then break end
				hum.WalkSpeed = hum.WalkSpeed + 1
				wait()
			end
		end
	end)

	UserInputService.InputEnded:Connect(function(input, isTyping)
		if isTyping then return end
		if input.KeyCode == Enum.KeyCode.LeftShift then
			speed = false
			repeat
				if speed == true then break end
				hum.WalkSpeed = hum.WalkSpeed - 1
				wait()
			until
			hum.WalkSpeed == 16
		end
	end)

yes in my demo the trail was enabled and disabled locally so its only visible locally and other players wont see the trails getting enabled or disabled

if you want others to see the trails then you will have to enable or disable them on a normal script on the server side

this can be done with remote events or the server could keep track of the characters speed and enable and disable them without remote events or another option is each client keeps track on all characters speed

How do I disable and enable the remote event tho? I know about the launch remoteevent thing but that’s what I used to do, with it being impossible to shut it off afterwards under 50 speed

You send the remote event like this to the server then the server will enable or disable the trails

local runService = game:GetService("RunService")

-- get the character
local character = script.Parent
-- get the root part
local rootPart = character.HumanoidRootPart
-- set enabled to false by default
local enabled = false

runService.Heartbeat:Connect(function()
	-- get the characters speed
	local speed = rootPart.AssemblyLinearVelocity.Magnitude
	
	if speed < 50 then
		-- if the speed is less then 50 and enabled is already false then just exit the function and do nothing
		if enabled == false then return end
		enabled = false
	else
		-- if the speed is more or equal to 50 and enabled is already true then just exit the function and do nothing
		if enabled == true then return end
		enabled = true
	end
	
	remoteEvent:FireServer(enabled)

	print("Trails:", enabled)
end)

do character:GetDescendants() instead of GetChildren, also wrap the loop with

spawn(function()

end)

that way the remote event also fires

i tried this and added the remoteevent directory, tho this adds the trails each time the player reaches speed 50 and doesnt remove them when they go under it, so basically it keeps adding more and more trails.

local runService = game:GetService("RunService")

-- get the character
local character = script.Parent
-- get the root part
local rootPart = character.HumanoidRootPart
-- set enabled to false by default
local enabled = false

local remoteevent = game.ReplicatedStorage.RemoteEvent

runService.Heartbeat:Connect(function()
	-- get the characters speed
	local speed = rootPart.AssemblyLinearVelocity.Magnitude
	
	if speed < 50 then
		-- if the speed is less then 50 and enabled is already false then just exit the function and do nothing
		if enabled == false then return end
		enabled = false
	else
		-- if the speed is more or equal to 50 and enabled is already true then just exit the function and do nothing
		if enabled == true then return end
		enabled = true
	end
	
	remoteevent:FireServer(enabled)

	print("Trails:", enabled)
end)

cant you reuse the same trails over and over again and simply do trail.Enabled = enabled to enable or disable them?

so you will use the CharacterAdded to add the trails to the character then inside the remote event you will enable or disable them but not create new ones

how would i do that without having to loop it?

How are you currently adding trails to the character?

this is the remoteevent script

local remoteevent = game.ReplicatedStorage.RemoteEvent
local trail = game.ServerStorage.Trail
local particle = game.ServerStorage.ParticleEmitter

remoteevent.OnServerEvent:Connect(function(player)
	local character = player.Character

	-- Trail 1
	local trail1 = trail:Clone()
	trail1.Parent = character
	local attachment0 = Instance.new("Attachment", character.Head)
	attachment0.Name = "TrailAttachment0"
	local attachment1 = Instance.new("Attachment", character.UpperTorso)
	attachment1.Name = "TrailAttachment1"

	trail1.Attachment0 = attachment0
	trail1.Attachment1 = attachment1

	-- Trail 2
	local trail2 = trail:Clone()
	trail2.Parent = character
	local attachment2 = Instance.new("Attachment", character.RightUpperArm)
	attachment2.Name = "TrailAttachment2"
	local attachment3 = Instance.new("Attachment", character.RightLowerArm)
	attachment3.Name = "TrailAttachment3"

	trail2.Attachment0 = attachment2
	trail2.Attachment1 = attachment3

	-- Trail 3
	local trail3 = trail:Clone()
	trail3.Parent = character
	local attachment4 = Instance.new("Attachment", character.RightLowerArm)
	attachment2.Name = "TrailAttachment4"
	local attachment5 = Instance.new("Attachment", character.RightHand)
	attachment3.Name = "TrailAttachment5"

	trail3.Attachment0 = attachment4
	trail3.Attachment1 = attachment5

	-- Trail 4
	local trail4 = trail:Clone()
	trail4.Parent = character
	local attachment6 = Instance.new("Attachment", character.LeftUpperArm)
	attachment6.Name = "TrailAttachment4"
	local attachment7 = Instance.new("Attachment", character.LeftLowerArm)
	attachment7.Name = "TrailAttachment5"

	trail4.Attachment0 = attachment6
	trail4.Attachment1 = attachment7

	-- Trail 5
	local trail5 = trail:Clone()
	trail5.Parent = character
	local attachment8 = Instance.new("Attachment", character.LeftLowerArm)
	attachment6.Name = "TrailAttachment4"
	local attachment9 = Instance.new("Attachment", character.LeftHand)
	attachment7.Name = "TrailAttachment5"

	trail5.Attachment0 = attachment8
	trail5.Attachment1 = attachment9
	
	-- Trail 6
	local trail6 = trail:Clone()
	trail6.Parent = character
	local attachment10 = Instance.new("Attachment", character.LowerTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment11 = Instance.new("Attachment", character.UpperTorso)
	attachment7.Name = "TrailAttachment5"

	trail6.Attachment0 = attachment10
	trail6.Attachment1 = attachment11
	
	-- Trail 7
	local trail7 = trail:Clone()
	trail7.Parent = character
	local attachment12 = Instance.new("Attachment", character.UpperTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment13 = Instance.new("Attachment", character.RightUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail7.Attachment0 = attachment12
	trail7.Attachment1 = attachment13
	
	-- Trail 8
	local trail8 = trail:Clone()
	trail8.Parent = character
	local attachment14 = Instance.new("Attachment", character.UpperTorso)
	attachment6.Name = "TrailAttachment4"
	local attachment15 = Instance.new("Attachment", character.LeftUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail8.Attachment0 = attachment14
	trail8.Attachment1 = attachment15
	
	-- Trail 9
	local trail9 = trail:Clone()
	trail9.Parent = character
	local attachment16 = Instance.new("Attachment", character.LeftUpperLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment17 = Instance.new("Attachment", character.LeftLowerLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail9.Attachment0 = attachment16
	trail9.Attachment1 = attachment17
	
	-- Trail 10
	local trail10 = trail:Clone()
	trail10.Parent = character
	local attachment18 = Instance.new("Attachment", character.LeftLowerLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment19 = Instance.new("Attachment", character.LeftFoot
	)
	attachment7.Name = "TrailAttachment5"

	trail10.Attachment0 = attachment18
	trail10.Attachment1 = attachment19
	
	-- Trail 11
	local trail11 = trail:Clone()
	trail11.Parent = character
	local attachment20 = Instance.new("Attachment", character.RightUpperLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment21 = Instance.new("Attachment", character.RightLowerLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail11.Attachment0 = attachment20
	trail11.Attachment1 = attachment21
	
	-- Trail 12
	local trail12 = trail:Clone()
	trail12.Parent = character
	local attachment22 = Instance.new("Attachment", character.RightLowerLeg)
	attachment6.Name = "TrailAttachment4"
	local attachment23 = Instance.new("Attachment", character.RightFoot
	)
	attachment7.Name = "TrailAttachment5"

	trail12.Attachment0 = attachment22
	trail12.Attachment1 = attachment23
	
	-- Trail 13
	local trail13 = trail:Clone()
	trail13.Parent = character
	local attachment24 = Instance.new("Attachment", character.LeftHand)
	attachment6.Name = "TrailAttachment4"
	local attachment25 = Instance.new("Attachment", character.LeftUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail13.Attachment0 = attachment24
	trail13.Attachment1 = attachment25
	
	-- Trail 14
	local trail14 = trail:Clone()
	trail14.Parent = character
	local attachment26 = Instance.new("Attachment", character.RightHand)
	attachment6.Name = "TrailAttachment4"
	local attachment27 = Instance.new("Attachment", character.RightUpperArm
	)
	attachment7.Name = "TrailAttachment5"

	trail14.Attachment0 = attachment26
	trail14.Attachment1 = attachment27
	
	-- Trail 15
	local trail15 = trail:Clone()
	trail15.Parent = character
	local attachment28 = Instance.new("Attachment", character.RightFoot)
	attachment6.Name = "TrailAttachment4"
	local attachment29 = Instance.new("Attachment", character.RightUpperLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail15.Attachment0 = attachment28
	trail15.Attachment1 = attachment29
	
	-- Trail 16
	local trail16 = trail:Clone()
	trail16.Parent = character
	local attachment30 = Instance.new("Attachment", character.LeftFoot)
	attachment6.Name = "TrailAttachment4"
	local attachment31 = Instance.new("Attachment", character.LeftUpperLeg
	)
	attachment7.Name = "TrailAttachment5"

	trail16.Attachment0 = attachment30
	trail16.Attachment1 = attachment31
	
	-- Trail 17
	local trail17 = trail:Clone()
	trail17.Parent = character
	local attachment32 = Instance.new("Attachment", character.UpperTorso
	)
	attachment6.Name = "TrailAttachment4"
	local attachment33 = Instance.new("Attachment", character.RootPart
	)
	attachment7.Name = "TrailAttachment5"

	trail17.Attachment0 = attachment32
	trail17.Attachment1 = attachment33
	
	local particle2 = particle:Clone()
	particle2.Enabled = true
	particle2.Parent = character.UpperTorso
	
	local particle3 = particle:Clone()
	particle3.Enabled = true
	particle3.Parent = character.LowerTorso
	
	local particle4 = particle:Clone()
	particle4.Enabled = true
	particle4.Parent = character.LeftFoot
	
	local particle5 = particle:Clone()
	particle5.Enabled = true
	particle5.Parent = character.LeftLowerLeg
	
	local particle6 = particle:Clone()
	particle6.Enabled = true
	particle6.Parent = character.LeftUpperLeg
	
	
	local particle7 = particle:Clone()
	particle7.Enabled = true
	particle7.Parent = character.RightFoot
	
	local particle8 = particle:Clone()
	particle8.Enabled = true
	particle8.Parent = character.RightLowerLeg
	
	local particle9 = particle:Clone()
	particle9.Enabled = true
	particle9.Parent = character.RightUpperLeg
	
	local particle10 = particle:Clone()
	particle10.Enabled = true
	particle10.Parent = character.LeftHand
	
	local particle11 = particle:Clone()
	particle11.Enabled = true
	particle11.Parent = character.LeftLowerArm
	
	local particle12 = particle:Clone()
	particle12.Enabled = true
	particle12.Parent = character.LeftUpperArm
	
	local particle13 = particle:Clone()
	particle13.Enabled = true
	particle13.Parent = character.RightHand
	
	local particle14 = particle:Clone()
	particle14.Enabled = true
	particle14.Parent = character.RightLowerArm
	
	local particle15 = particle:Clone()
	particle15.Enabled = true
	particle15.Parent = character.RightUpperArm

end)

i should also add, the particles should appear and dissapear with the trails but its currently broken so i didnt add it in this topic

local trails = {}

-- this function creates a trail
local function CreateTrail(character, part1, part2)
	local attachment0 = Instance.new("Attachment", part1)
	local attachment1 = Instance.new("Attachment", part2)
	local trail = game.ServerStorage.Trail:Clone()
	trail.Attachment0 = attachment0
	trail.Attachment1 = attachment1
	trail.Parent = character
	return trail
end

-- when a player enters the game call this function
game.Players.PlayerAdded:Connect(function(player)
	-- when the players character is added call this function
	player.CharacterAddedLConnect(function(character)
		-- this is where we store the trails for each player
		trails[player] = {}
		--  add some trails to the table
		table.insert(trails[player], CreateTrail(character, character.Head, character.UpperTorso))
		table.insert(trails[player], CreateTrail(character, character.RightUpperArm, character.RightLowerArm))
		table.insert(trails[player], CreateTrail(character, character.RightLowerArm, character.RightHand))
		table.insert(trails[player], CreateTrail(character, character.LeftUpperArm, character.LeftLowerArm))
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	-- when the player leaves set there table to nil so we don't get a memory leak
	trails[player] = nil
end)

remoteevent.OnServerEvent:Connect(function(player, enabled)
	-- when the player sends a event enable or disable the trails
	for i, trail in trails[player] do
		trail.Enabled = enabled
	end
end)

what am i supposed to change to match the amount of trails i already had?

what if we were to launch the remoteevent on player join but with the trails and particles disabled and then enable and disable with the speed script?