I've recently started making a gun script and everything seems to be working fine, but whenever I click on something that isn't the empty void, the bullet goes in a slightly different direction.

local re = script.Parent.RE

re.OnServerEvent:Connect(function(player, mouse)
	local h = mouse.Hit
	local p = h.p
	local s = script.Parent.Barrel.Position
	
	local b = Instance.new("Part", workspace)
	b.Size = Vector3.new(.25,.25,.25)
	b.Transparency = 1
	b.Position = s
	b.CanCollide = false
	
	local t = Instance.new("Trail", b)
	t.FaceCamera = true
	t.Lifetime = .75
	t.MinLength = .15	
	t.LightEmission = 0.25
	
	local aa = Instance.new("Attachment", b)
	aa.Position = Vector3.new(0.35, 0, 0)
	aa.Name = "Attachment1"
	local ab = Instance.new("Attachment", b)
	ab.Position = Vector3.new(-0.35, 0, 0)
	ab.Name = "Attachment1"
			
	t.Attachment0 = aa
	t.Attachment1 = ab
	
	local bv = Instance.new("BodyVelocity", b)
	bv.MaxForce = Vector3.new(9e9, 9e9, 9e9)
	bv.Velocity = (p*100)
	
	wait(3)
	if b then
		b:Destroy()
	end
end)

This is my first time making a gun, so any help is appreciated!

6 comments

0

You can’t get the Mouse on the server.

0

You can get the Mouse.Hit by passing it as a parameter on the server, but can’t pass the mouse object itself.

0

I moved the GetMouse() to the local script

0

No no no, you passed the mouse as a parameter. Remove it.

0

What do I remove and what do I put instead?

0

Remove the mouse parameter, and put the mouse’s Hit as a parameter instead, and when you FireServer the remote, include the hit as an argument