So i made a gun. And it works fine. But if i aim, and shoot, it collides with the muzzle, so the bullet doesnt go anywhere. If i dont aim, it works fine. Why is that?

function script:

function shoot()
	if not reloading then
		if ammo.Value > 0 then
			if not changingmodes then
				if not idk then
                  if not runnin then
				aui.Frame.bullets.Text = ammo.Value.."/"..clips.Value
						local sound = selectedgun.Sound
	local ss = sound:Clone()
	ss.Playing = true
	ss.Parent = cam
	
	game:GetService("Debris"):AddItem(ss,2)
	local ray = Ray.new(selectedgun.Thingy.CFrame.p, (m.Hit.p - selectedgun.Thingy.CFrame.p).unit * 300)
	local part, position = workspace:FindPartOnRay(ray, p.Character, false, true)
	local b = Instance.new("Part")
	b.CanCollide = false
	b.Anchored = true
	b.Transparency = 0
	b.Size = Vector3.new(1.25, 0.25, 0.25)
	re = re * gunds.shooten
	local distance = (selectedgun.Thingy.CFrame.p - position).magnitude
		b.Size = Vector3.new(1, 1, 1)
		b.CFrame = CFrame.new(selectedgun.Thingy.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
		game:GetService("Debris"):AddItem(b, 0.1)
		local bh = misc.bullethole:Clone()
		bh.Parent = workspace
		bh.CFrame = CFrame.new(position)
		game:GetService("Debris"):AddItem(bh,3)
		if part then
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	
	if not humanoid then
		humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
	end
	
	if humanoid then       
		if part.Name == "Head" then
					humanoid:TakeDamage(50*2)

					print("hEaDsHoT")
		else
					humanoid:TakeDamage(30)
		end
	end
		end
					ammo.Value = ammo.Value - 1
			end
			end
	else
	end
	aui.Frame.bullets.Text = ammo.Value.."/"..clips.Value
	if settings.something.Value == 1 then
	aui.Frame.mode.Text = "Automatic"
end
	
			end
			end
			
end

thanks for helping!

2 comments

0

Try making your muzzle's cancollide off?

0

it already is.