(Help please) Make gun always shoot at your cursor

I want an automatic gun to shoot at your cursor continuously.

When you hold down the gun, it only shoots where you first clicked.

It might be the InputGateway, Also listed in the model.

By the way, i am restoring models and this is a very old model so it may be very deprecated or messy. Its a raycast rifle, so im sorry i guess.

Model link because it might be in any of the other scripts. (open source)


1 Like

You need to detect the InputBegan and InputEnded events on the client. If InputBegan then fire a remote to the server with MousePos. A InputEnded, stop firing remote. On server side, fire projectile/ray./whatever towards MousePos.

Quick dirty code:

UserInputService.InputBegan:Connect(function (input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and Mouse ~= nil then
		IsMouseDown = true

UserInputService.InputEnded:Connect(function (input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and Mouse ~= nil then
		IsMouseDown = false

game:GetService("RunService").Stepped:Connect(function ()
	if IsMouseDown then
		MouseEvent:FireServer(Mouse.Hit.Position) -- A RemoteEvent to send MousePos to server

server script

MouseEvent.OnServerEvent:Connect(function (clientThatFired, mousePoint)
	-- fire bullets towards MousePos
1 Like

Nows it telling me that
Workspace.Frostilism.InputGateway.Server:24: Argument #1 should be a boolean describing the activation state of the tool.

activation.OnServerEvent:Connect(function (clientThatFired, mousePoint)
	local humanoid = char:FindFirstChildWhichIsA("Humanoid")
	if humanoid then		
		local tool = char:FindFirstChildWhichIsA("Tool")
		if tool then
			local player = game.Players:GetPlayerFromCharacter(char)

			assert(clientThatFired == player, INVALID_SENDING_PLAYER)
			assert(typeof(down) == "boolean", BAD_ARG_NUM1)
			assert(typeof(mousePoint) == "CFrame", BAD_ARG_NUM2)

			humanoid.TargetPoint = mousePoint.Position

Just comment out this line:

assert(typeof(down) == "boolean", BAD_ARG_NUM1)

Obvs ARG1 in the example is the mpousePoint CFrame and not a Bool

all types of asserts are messing with my code.
Now my shots just go into the origin of the map.

OK, so it is either not sending MousePos via the RemoteEvent, or the server when it fires is not using the MousePos as it’s target point. Just try printing the values at each step and see where it changes