My bullet go anywhere if I aims a part, is it a problematic because is a little the aim of game and I don't know how to fix this problem:/ so can someone help me? Thank for your answers and your explanations:)

Gyazo GIF

function makingBullet()
	local bullet = Instance.new("Part", workspace.Debris)
	bullet.FormFactor = "Custom"
	bullet.TopSurface = 0
	bullet.BottomSurface = 0
	bullet.Anchored = false
	bullet.CanCollide = false
	bullet.Size = Vector3.new(0.1, 0.1, 1.8)
	bullet.Material = 'Neon'
	bullet.BrickColor = BrickColor.new('Daisy orange')
	
	local Script = script.DamageScript:Clone()
	Script.Parent = bullet
	
	game:GetService('Debris'):AddItem(bullet, 10)
	
	return bullet
end

function NPC_Module.FireBullet(mouse, player)
	local bullet = makingBullet()
	
	player.Character.Header.AimPart.Shot:Play()
	
	bullet.Name = player.Name
	if workspace:FindFirstChild('Debris') ~= nil then
		bullet.Parent = workspace.Debris
	else
		local DebrisFolder = Instance.new('Folder', workspace)
		DebrisFolder.Name = 'Debris'
		bullet.Parent = DebrisFolder
	end
	
	bullet.DamageScript.Disabled = false
	
	local BodyVelocity = Instance.new('BodyVelocity')
	BodyVelocity.Parent = bullet
	BodyVelocity.Velocity = (mouse.Hit.p-bullet.Position).unit*120
	bullet.CFrame = CFrame.new(player.Character.Header.AimPart.Position,mouse.Hit.p)
end

3 comments

1

The bullet.CFrame line should go before you set the BodyVelocity.

0

In more you told me in my other post lol excuse me: ')

0

It should be game.Debris, not workspace.Debris.