How do I fix this trail

Making Guns for my game and thought it would look nice if the trail follows the bullet so I tweened the bullet and a trail but for some reason the trail isn’t connected to the bullet and it’s far away from the gun. Here is a video to show what I mean

robloxapp-20210506-0822348.wmv (966.4 KB)

And here is the code that I made

-- Tweening bullet --
	local bullet = ServerStorage.Bullet:Clone()
	bullet.CFrame = CFrame.new(origin, intersection)*CFrame.new(0, 0, -1)
	bullet.Parent = Workspace
	local speed = distance/50
	local tweenInfo = TweenInfo.new(speed,Enum.EasingStyle.Linear)
	local goal = {}
	goal.Position = position
	
	
	-- Tweening Trail --
	local attachment0 = Instance.new("Attachment")
	attachment0.Name = "Attachment0"
	attachment0.Parent = bullet
	attachment0.Position = origin
	
	local attachment1 = Instance.new("Attachment")
	attachment1.Name = "Attachment1"
	attachment1.Parent = bullet
	attachment1.Position = position
	
	local trail = Instance.new("Trail")
	trail.Parent = bullet
	trail.Attachment0 = attachment0
	trail.Attachment1 = attachment1
	local color1 = Color3.new(15/255,127/255,254/255)
	local color2 = Color3.new(255/255,255/255,255/255)
	trail.Color = ColorSequence.new(color1, color2)
	
	local TweenService = game:GetService("TweenService")

	local tween = TweenService:Create(bullet, tweenInfo, goal)
	tween:Play()

Without the position and orgin variable values I can’t be of any use to you. However, instead of creating a new instance and trail for the bullet I would recommend manually setting up the trail and attachments inside the original bullet itself and making sure that it works. Then whenever you clone the bullet it will clone with the attachments and trail. Make sure the trail is a child of the original bullet though.

However, if you are dead-set on creating new attachments for each individual bullet you clone then you should use this:

local bulletTemplate = ServerStorage.Bullet
local orgin = Vector3.new(bulletTemplate.Size.X * 0.5, 0, bulletTemplate.Size.Z * 0.5)
local position = Vector3.new(bulletTemplate.Size.X * -0.5, 0, bulletTemplate.Size.Z * 0.5)


In your code you use CFrame.new(origin, intersection). This feature has been deprecated for the new constructor. You should instead use CFrame.lookAt(orgin, intersection).
Also, it’s usually a not good practice to create new instances whenever you create a gun, as this can cause lag or reduced performance. Instead it’s a good practice to use PartCache, for all your quick part-creation needs for this, as it will reduce lag caused by instancing and reparenting greatly.

Origin is the barrel of the gun and position is where the bullet will end up. I tried just manually making the attachments and trails but it is still the same result. Any other ideas?

You should create the attachments as children of the bullet. Use Vector3.new(bulletTemplate.Size.X * 0.5, 0, bulletTemplate.Size.Z * 0.5) on one attachment for its position and Vector3.new(bulletTemplate.Size.X * -0.5, 0, bulletTemplate.Size.Z * 0.5) on the other.

Also, try editing the properties of the trail.

the attachments were already children of the bullet and the the properties of the trail won’t fix this.

Here. Try using this:

https://www.roblox.com/library/6776840993/Bullet

You may be able to learn how to set up the attachments from it.

For some reason I can’t upload a video but its pretty much the same result just the trail is different because I used the part you sent. Do you want me to send the whole gun I am using. By the way thanks for the help you have been giving me I appreciate it.