this script should add trails from serverstorage when the player reaches 30 speed and remove them when he goes below, like most “the flash” games to create the iconic lightning effect. this is a localscript located in workspace, no errors, it doesnt work.
local serverStorage = game:GetService("ServerStorage")
local runService = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or script.Parent
local humanoid = character.Humanoid
runService.Heartbeat:Connect(function()
if humanoid.WalkSpeed > 30 then
-- Add trails
local trail = serverStorage.Trail:Clone()
trail.Parent = character
trail.Visible = true
local attachment0 = Instance.new("Attachment", character.Head)
attachment0.Name = "TrailAttachment0"
local attachment1 = Instance.new("Attachment", character.UpperTorso)
attachment1.Name = "TrailAttachment1"
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
else
-- Remove trails
for _, child in pairs(character:GetChildren()) do
if child:IsA("Trail") then
child:Destroy()
end
end
end
end)
instead of doing a heartbeat, you could just do a loop that checks the speed every time it changes. this probably wont fix your issue but it might
local serverStorage = game:GetService("ServerStorage")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or script.Parent
local humanoid = character.Humanoid
character.Humanoid.WalkSpeed.Changed:Connect(function(newSpeed)
if newSpeed >= 30 then
local trail = serverStorage.Trail:Clone()
trail.Parent = character
trail.Visible = true
local attachment0 = Instance.new("Attachment", character.Head)
attachment0.Name = "TrailAttachment0"
local attachment1 = Instance.new("Attachment", character.UpperTorso)
attachment1.Name = "TrailAttachment1"
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
else
-- Remove trails
for _, child in pairs(character:GetChildren()) do
if child:IsA("Trail") then
child:Destroy()
end
end
end
end)
this could be happening because you’re doing all of this in a local script. try firing a remote event when their speed is over 30 and then add the trail on the server
i added a script inside workspace to add the remoteevent
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "AddTrail"
remoteEvent.Parent = replicatedStorage
then i added this script into starterplayerscripts
local player = game:GetService("Players").LocalPlayer
local character = player.Character or script.Parent
local humanoid = character.Humanoid
local remoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
game:GetService("RunService").Heartbeat:Connect(function()
if humanoid.WalkSpeed > 30 then
remoteEvent:FireServer()
end
end)
and at last this one in serverscriptservice
local serverStorage = game:GetService("ServerStorage")
local remoteEvent = game:GetService("ReplicatedStorage").RemoteEvent
remoteEvent.OnServerEvent:Connect(function(player)
local character = player.Character
local trail = serverStorage.Trail:Clone()
trail.Parent = character
local attachment0 = Instance.new("Attachment", character.Head)
attachment0.Name = "TrailAttachment0"
local attachment1 = Instance.new("Attachment", character.UpperTorso)
attachment1.Name = "TrailAttachment1"
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1
end)