Trail not shooting in right direction

so i have a gun system that shoots fine but i wanted to make a trail for a bullet kind of but it isnt working right

local Origin = ShootPart.WorldPosition
					local Direction = (Received.Position-Origin).Unit*3000
					local Raycast = workspace:Raycast(Origin,Direction)

					local Intersection = Raycast and Raycast.Position or Origin + Direction
					local Distance = (Origin - Intersection).Magnitude
					
					
					local Trail
					if not Tool.Handle:FindFirstChildOfClass("Trail") then
						Trail = Instance.new("Trail")
					else
						Trail = Tool.Handle:FindFirstChildOfClass("Trail")
					end
					
					Trail.Parent = Tool.Handle
					Trail.Lifetime = 0.5 -- Adjust the value to control the trail's visibility duration
					Trail.Enabled = false
					Trail.Transparency = NumberSequence.new(0.5)
					Trail.Color = ColorSequence.new(Player.BulletColor.Value)
					Trail.MaxLength = .1
					
				
					
					local function createBulletTrail(Origin, Intersection, Distance)
						Trail.Enabled = true
						Trail.TextureMode = Enum.TextureMode.Static -- Adjust this if you want the texture to stretch along the trail

						
						
						
						
						local endAttachment
						if not Tool.Handle:FindFirstChild("End") then
							endAttachment = Instance.new("Attachment")
							endAttachment.Name = "End"
						else
							endAttachment = Tool.Handle:FindFirstChild("End")
						end
						
						
						
						endAttachment.Parent = Tool.Handle
						endAttachment.Position = -Raycast.Position
						
						
						
						Trail.Attachment0 = Tool.Handle.Attachment
						Trail.Attachment1 = endAttachment

						wait(Do.Cooldown) -- Adjust this delay to control how long the trail stays visible
						Trail.Enabled = false
					end

					-- In the RemoteEvent.OnServerEvent function:

					if Do.Visualize == true then
						createBulletTrail(Origin, Intersection, Distance)
					end

Received is the mouse pos sent from the client

robloxapp-20230726-1254150

Not sure if this will fix it, but it’s worth a shot.

Replace this:

endAttachment.Position = -Raycast.Position

With this:

endAttachment.WorldPosition = Raycast.Position

it was broken with that as well that’s
why I changed it to test :sob:

The trail should be shot straight out of the gun barrel since that is where it’s aiming. It looks strange with your aiming movements still pointing forward while shooting the NPC on the left.

Anyway, what is the or for in the beginning of the script?
local Intersection = Raycast and Raycast.Position or Origin + Direction

See what happens when you use just one of the 2 items.

robloxapp-20230726-1412051
this is how i want to make it

hi!

here’s what you need to make a trail:

local lenght = (startpoint-endpoint).magnitude
local cframe = CFrame.new((startpoint+endpoint)/2, endpoint)
local size = Vector3.new(0.25,0.25,lenght)

They’re not making a Part trail, they’re making an actual Trail between 2 attachment points.

@UncleBanard did you try my suggestion about removing the or?

Try putting in print statements that allow you to see what each variable is in your statements?
For example try this ahead of your Intersection calculating line:

print("Raycast: ", Raycast, "    Raycast.Position: ", Raycast.Position, "   Origin: , Origin, "      Direction: ", Direction)
local Intersection = Raycast and Raycast.Position or Origin + Direction

heyo!

the part can act as the trail, he just add attachments to both ends of the part and connect them via the trail instance.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.