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

