Why does it just teleport?

so i want to make a gun shoot out a random part. but for some reason it just teleports to the position and it doesn’t shoot the part out of the gun.

local Folder = script.Parent
local FuncFolder = Folder.Parent
local Tool = FuncFolder.Parent

local Event = FuncFolder.Events.Shoot
local Debris = game:GetService("Debris")

Event.OnServerEvent:Connect(function(plr)
	local Pixel = game.ServerStorage.PixelStorage.Pixel:Clone()
	Pixel.Parent = workspace.addedPixels
	
	local gun = Tool.Handle
	local gunPosition = gun.Position
	local gunDirection = (gun.CFrame * CFrame.new(0, 0, -5)).Position - gunPosition
	
	Pixel.Position = gunPosition - gunDirection.Unit * 10
	
	local LinearVelocity = Instance.new("LinearVelocity")
	LinearVelocity.Parent = Pixel
	LinearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
	LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
	LinearVelocity.VectorVelocity = gunDirection.Unit * 50
	
	Debris:AddItem(Pixel,35)
	
	task.wait(3)
	
	LinearVelocity:Destroy()
end)

when you activate the gun, the object will just appear a bit infront of the gun and not shoot out of the gun. i checked if it had anything to do with anchoring the part, but the part is unanchored.
so it should work right?

Thanks in advance!

1 Like

do like:

local velocity = gunDirection + Pixel.Position * 30 or smth like that