Bulletray not originating from right position

Hi I’m making a shotgun and I’ve been stuck with this issue of the bulletrays not originating from the correct position (shootpart) for a long time now. My intention is for the rays to emerge from the end of the barrel (bead) of the shotgun aka the basepart you see at the location. However, the rays emerge from midair.


Alternative: robloxapp-20240323-1511045.wmv (1.7 MB)

Hierachy:

Code for raycast and bulletspawning:

for i = 1, Projectiles do
			task.spawn(function()
				local direction = CFrame.new(Shotgun.ShootPart.Position,hitpos)*CFrame.Angles(math.rad(rnd:NextNumber(-Spread, Spread)), math.rad(rnd:NextNumber(-Spread, Spread)), 0 )
				local ray = workspace:Raycast(Shotgun.ShootPart.Position,direction.LookVector * MaxRange, Params)
				
				local intersection = ray.Position
				local traveldistance = (Shotgun.ShootPart.Position - intersection).Magnitude
				local bulletray = game.ServerStorage.Misc.BulletRay:Clone()

				bulletray.CFrame = CFrame.lookAt(Shotgun.ShootPart.Position, intersection) *CFrame.new(0, 0, -traveldistance/2)
				bulletray.Size = Vector3.new(0.05, 0.05, traveldistance)
				Debris:AddItem(bulletray, 0.15)
				bulletray.Parent = workspace
			end)
		end

I was able to find out that the problem was that the shootpart position was not being recorded properly.
I’m not sure why this is the case, but the position of the shootpart despite being obviously from the greypart, the script reports it in a different area.

robloxapp-20240323-1523487.wmv (982.0 KB)

Origin and the actual shootpart.position is different:

How can I fix this issue?

Found the solution. Apparently it was because of the fact that I used a local script to update the Motor6D for the player. However, the same method worked for another gun but not for this.

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