Make Gun Follow Mouse Not Working Right

I have a script to make the gun firepos follow a humanoid when it detects a humanoids body part, but since the gun is welded and i have to keep it welded to connect the parts it does this happends.

image

localscript

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Move:Connect(function(hit)
	if mouse.Target  then
		if mouse.Target.Parent:FindFirstChild("Humanoid") then
			script.Parent.rotateRE:FireServer(mouse.Target.Position)
		end
	end
end)

serverscript

script.Parent.rotateRE.OnServerEvent:Connect(function(plr,pos)
	script.Parent.CFrame = CFrame.lookAt(script.Parent.Position,pos)
end)

this does not make the actual gun visually follow the mouse, it just shoots the bullets to the direction of the players mouse but it doesn’t work the way i want it to.

nvm i found out how to do it a different way i did the same thing but to the bullet instead and since the bullet has an applied forward force relative to attachment0 i pointed the bullet to the mosue cursor poisition and then it worked

I got mouse.hit.poisiton on the client , then remote vent fire to server with the info then make bullet rotate the way using cframe.lookat mouse hit poisiton

Mark this as the solution then.

1 Like

Let everyone know how you solved it so your Solution can help people that are having the same problem.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.