Most efficient way to receive Mouse.Hit?

lets say i have an automatic weapon and i want it to shoot every 0.1s.
what is the best way to receive the player’s mouse location?

i could send a remote event every 0.1s, i could make a remote function to receive the mouse location every 0.2s the weapon is active, but are there any other methods?

that seems horribly unoptimized and i’m sure there’s a better way… is there?

2 Likes

This is exactly what unreliable remote events are optimized for.

2 Likes

since it’s an automatic weapon you can send a remote event when the player “Holds” the button indicating start then the server will fire each 0.1s until he gets an ended signal

not a good code just for demonstration

local active = false

FireStart.OnServerEvent:Connect(function()
	active = true
	while active and thereIsAmmo do
		-- FIRE Logic
		
		task.wait()
	end
end)

FireEnd.OnServerEvent:Connect(function()
	active = false
end)

and you can send another remote event to the server to update the mouse position but check on the client if the new mouse position isn’t the same as the old one before sending the event

there may be better methods than this but that is what I came up with

1 Like

aren’t they unreliable? i haven’t personally had enough experience around them to know for sure. i tend to use them for effects or things that don’t affect gameplay. should i be using them for stuff like this?

1 Like

ooh

can you PLEASE elaborate on how you could use an unreliable remote event for this
pleaseeeeee

2 Likes

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