I’m attempting to add a trail to a projectile. I’m missing something but I’m unsure what.
task.wait(5)
local barrel = script.Parent
while task.wait(0.5) do
local bullet = Instance.new("Part")
bullet.Name = "Bullet"
bullet.Shape = "Ball"
bullet.Material = Enum.Material.Neon
bullet.Color = Color3.new(1, 0.333333, 0)
bullet.Size = Vector3.new(0.2, 0.2, 0.2)
bullet.CanCollide = false
bullet.Anchored = false
bullet.CFrame = CFrame.new(barrel.CFrame.X, barrel.CFrame.Y, barrel.CFrame.Z)
bullet.Parent = barrel
task.wait()
local att = Instance.new("Attachment")
att.Parent = bullet
--attempting to add a trail to the projectile
local trailAtt1 = Instance.new("Attachment")
trailAtt1.Name = "TrailAttachment1"
trailAtt1.CFrame = bullet.CFrame + Vector3.new(0, bullet.Size.Y/2, 0)
trailAtt1.Parent = bullet
local trailAtt2 = Instance.new("Attachment")
trailAtt2.Name = "TrailAttachment2"
trailAtt2.CFrame = bullet.CFrame - Vector3.new(0, bullet.Size.Y/2, 0)
trailAtt2.Parent = bullet
local trail = Instance.new("Trail")
trail.Color = ColorSequence.new(bullet.Color)
trail.Attachment0 = trailAtt1
trail.Attachment1 = trailAtt2
trail.Transparency = NumberSequence.new(0, 1)
trail.Lifetime = 0.5
trail.Parent = bullet
local lv = Instance.new("LinearVelocity")
lv.MaxForce = 9999999
lv.Attachment0 = att
lv.VectorVelocity = barrel.CFrame.LookVector * 10 --default 100
lv.Parent = att
game:GetService("Debris"):AddItem(bullet, 10) --default 1
end