this script should insert a trail that i keep in server storage into the specified player parts when the player goes above a certain speed and then also remove them when they go below:
situated in ServerScriptService a server side script:
local remoteevent = game.ReplicatedStorage.RemoteEvent
local trail = game.ServerStorage.Trail
local Particle = game.ServerStorage:WaitForChild("ParticleEmitter").ParticleEmitter
remoteevent.OnClientEvent: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)
attachment4.Name = "TrailAttachment4"
local attachment5 = Instance.new("Attachment", character.RightHand)
attachment5.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)
attachment8.Name = "TrailAttachment6"
local attachment9 = Instance.new("Attachment", character.LeftHand)
attachment9.Name = "TrailAttachment7"
trail5.Attachment0 = attachment8
trail5.Attachment1 = attachment9
-- Trail 6
local trail6 = trail:Clone()
trail6.Parent = character
local attachment10 = Instance.new("Attachment", character.LowerTorso)
attachment10.Name = "TrailAttachment8"
local attachment11 = Instance.new("Attachment", character.UpperTorso)
attachment11.Name = "TrailAttachment9"
trail6.Attachment0 = attachment10
trail6.Attachment1 = attachment11
-- Trail 7
local trail7 = trail:Clone()
trail7.Parent = character
local attachment12 = Instance.new("Attachment", character.UpperTorso)
attachment12.Name = "TrailAttachment10"
local attachment13 = Instance.new("Attachment", character.RightUpperArm)
attachment13.Name = "TrailAttachment11"
trail7.Attachment0 = attachment12
trail7.Attachment1 = attachment13
-- Trail 8
local trail8 = trail:Clone()
trail8.Parent = character
local attachment14 = Instance.new("Attachment", character.UpperTorso)
attachment14.Name = "TrailAttachment12"
local attachment15 = Instance.new("Attachment", character.LeftUpperArm)
attachment15.Name = "TrailAttachment13"
trail8.Attachment0 = attachment14
trail8.Attachment1 = attachment15
-- Trail 9
local trail9 = trail:Clone()
trail9.Parent = character
local attachment16 = Instance.new("Attachment", character.UpperTorso)
attachment16.Name = "TrailAttachment14"
local attachment17 = Instance.new("Attachment", character.RightUpperLeg)
attachment17.Name = "TrailAttachment15"
trail9.Attachment0 = attachment16
trail9.Attachment1 = attachment17
-- Trail 10
local trail10 = trail:Clone()
trail10.Parent = character
local attachment18 = Instance.new("Attachment", character.UpperTorso)
attachment18.Name = "TrailAttachment16"
local attachment19 = Instance.new("Attachment", character.LeftUpperLeg)
attachment19.Name = "TrailAttachment17"
trail10.Attachment0 = attachment18
trail10.Attachment1 = attachment19
-- Trail 11
local trail11 = trail:Clone()
trail11.Parent = character
local attachment20 = Instance.new("Attachment", character.RightUpperLeg)
attachment20.Name = "TrailAttachment18"
local attachment21 = Instance.new("Attachment", character.RightLowerLeg)
attachment21.Name = "TrailAttachment19"
trail11.Attachment0 = attachment20
trail11.Attachment1 = attachment21
-- Trail 12
local trail12 = trail:Clone()
trail12.Parent = character
local attachment22 = Instance.new("Attachment", character.RightLowerLeg)
attachment22.Name = "TrailAttachment20"
local attachment23 = Instance.new("Attachment", character.RightFoot)
attachment23.Name = "TrailAttachment21"
trail12.Attachment0 = attachment22
trail12.Attachment1 = attachment23
-- Trail 13
local trail13 = trail:Clone()
trail13.Parent = character
local attachment24 = Instance.new("Attachment", character.LeftUpperLeg)
attachment24.Name = "TrailAttachment22"
local attachment25 = Instance.new("Attachment", character.LeftLowerLeg)
attachment25.Name = "TrailAttachment23"
trail13.Attachment0 = attachment24
trail13.Attachment1 = attachment25
-- Trail 14
local trail14 = trail:Clone()
trail14.Parent = character
local attachment26 = Instance.new("Attachment", character.LeftLowerLeg)
attachment26.Name = "TrailAttachment24"
local attachment27 = Instance.new("Attachment", character.LeftFoot)
attachment27.Name = "TrailAttachment25"
trail14.Attachment0 = attachment26
trail14.Attachment1 = attachment27
-- Trail 15
local trail15 = trail:Clone()
trail15.Parent = character
local attachment28 = Instance.new("Attachment", character.LowerTorso)
attachment28.Name = "TrailAttachment26"
local attachment29 = Instance.new("Attachment", character.RightUpperLeg)
attachment29.Name = "TrailAttachment27"
trail15.Attachment0 = attachment28
trail15.Attachment1 = attachment29
-- Trail 16
local trail16 = trail:Clone()
trail16.Parent = character
local attachment30 = Instance.new("Attachment", character.LowerTorso)
attachment30.Name = "TrailAttachment28"
local attachment31 = Instance.new("Attachment", character.LeftUpperLeg)
attachment31.Name = "TrailAttachment29"
trail16.Attachment0 = attachment30
trail16.Attachment1 = attachment31
-- Add particle effect
local particle = Particle:Clone()
particle.Parent = character.Head
particle.Enabled = true
end)
situated in StarterCharacterScripts in a localscript:
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
-- create a empty table where we will save all the characters trails
local trails = {}
-- loop all descendants of the character and add any tails to the trails table
for i, child in character:GetDescendants() do
if child.ClassName ~= "Trail" then continue end
table.insert(trails, child)
end
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
-- enables or disable all trails
for i, trail in trails do
trail.Enabled = enabled
end
print("Trails:", enabled)
end)