(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)
https://www.roblox.com/library/10528665510


`

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:
localscript:

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

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

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

server script

MouseEvent.OnServerEvent:Connect(function (clientThatFired, mousePoint)
	-- fire bullets towards MousePos
end)
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
			tool:Activate()
end
	end
end)

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

bump
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