Gun Teleportation

Hello, I’m trying to make a gun, but for some reason I can’t seem to figure out what’s wrong. So whenever I shoot the gun it teleports at a random location.

(Also I set size to 25 because it’s easier to see).

Script:

local Event = game:GetService("ReplicatedStorage"):WaitForChild("GunEvent")

function Bullet(mousePos,Handle,damage)
	local Bullet = Instance.new("Part")
	Bullet.Name = "Bullet"
	Bullet.Shape = Enum.PartType.Ball
	Bullet.Size = Vector3.new(25,25,25)
	Bullet.Position = Handle.Position
	print(Handle.Position)
	Bullet.Material = Enum.Material.CorrodedMetal
	Bullet.BrickColor = BrickColor.new("Rust")
	Bullet.CanCollide = false
	--Bullet.Anchored = true
	Bullet.Parent = workspace
	--Bullet:SetNetworkOwner(nil)

	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	BodyVelocity.Velocity = (mousePos-Handle.Position) * 100
	BodyVelocity.Parent = Bullet

	--[[local debris = game:GetService("Debris")
	debris:AddItem(Bullet,0.5)]]
	
	Bullet.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			if hit.Name == "Head" then
				humanoid:TakeDamage(damage*2)
			else
				humanoid:TakeDamage(damage)
			end	
		end
	end)
end

Event.OnServerEvent:Connect(function(player,mousePos,Handle,damage)
	Bullet(mousePos,Handle,damage)
end)

Thank you.

Edit: I forgot I had to go now so sorry. I won’t be able to respond for quiet a while.

2 Likes

BodyVelocity.Velocity = (mousePos-Handle.Position).Unit * 100

2 Likes