Projectile trail glitched when there is structures

  1. What do you want to achieve?
    A gun system

  2. What is the issue?
    The bullet projectile looks glitched whenever I shoot near structures and walls but it looks normal when the area is almost empty

  3. What solutions have you tried so far?
    I was looking through the devforum but I haven’t found a solution

The gun uses FastCast and the bullet is in ReplicatedStorage and it has a trail inside

Video of the problem:

Video of how it’s supposed to work:

Any help would be appreciated.

If its indoor and has a trail then fastcast needs this fix

After implementing that, the bullet does go in the right direction but for some reason its too slow

Probably due to the ray hit function, try changing the distance factor to something like this.

Im at work so I cant explain why or test it out btw. Just my gut feeling based on memory.

            local direction = result.Position - bullet.Position
            local originalPosition = bullet.Position
            task.wait()
            print("Move 1")
            bullet.CFrame = bullet.CFrame + direction*0.95
            task.wait()
            print("Move 2")
            bullet.CFrame = bullet.CFrame + direction*0.05
        end

I am not sure how I will implement it into the ray hit function
Do you know how?

function Hit(Cast,Result)
	local Hit = Result.Instance
	if Hit then
		local humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid") or Hit.Parent.Parent:FindFirstChildOfClass("Humanoid")
		if humanoid then
			UntagHumanoid(humanoid)
			TagHumanoid(humanoid, game:GetService("Players"):GetPlayerFromCharacter(Gun.Parent))
			humanoid:TakeDamage(Settings.Damage)
		end
	end
end