Update Mouse.Hit.Position without using remote events?

Hello!

I am currently attempting to make a simple gun system. Here’s my current logic:

User clicks on their left Mouse (and holds it down)
A remote event is fired once to the server (raycasting, raycast repeats and keeps raycasting)
User releases their mouse
A second remote event is fired (raycast stops raycasting)

There’s a simple issue, the MousePosition stays the same since the remote event fires only once for the raycast to start raycasting, meaning it will raycast at the same position. I could fix this by simply firing a remote event every time someone clicks on their mouse (so that mouse.hit.position keeps updating) but that wouldn’t be great for performance.

So, I was wondering if there was a better way to do this?
Thanks in advance.

1 Like

There is no way to access the mouse from the server.

1 Like

So, every time someone would shoot their gun (by holding down their mouse) I’d have to fire the remote?? Wouldn’t that downgrade performance a lot?

Roblox simply never replicates the mouse due to performance on their end so yes it will be harsh on performance however maybe only send it when the mouse moves.

1 Like

Try this

local buttonPressed = false

Mouse.Button1Down:Connect(function()
buttonPressed = true
end)

Mouse.Button1Up:Connect(function()
buttonPressed = false
end)

RunService.Heartbeat:Connect(function()
if buttonPressed then
Remote:FireServer(mouse)
end
end)

Server:

Remote.OnServerEvent:Connect(function(player, mouse)
-- do something
end)

This is the performance implication he didn’t want…

It, never make my performance down, however
:wink:

Poor mobile users won’t like that script very much. :frowning:

Yeah, you right. It can make them lagging very much

Maybe you’re already doing it this way, but I usually see people rendering the bullets on the client and verifying it on the server then replicating it to other clients nearby (or all) to ensure that the player shooting has a good experience with the system, maybe its a misleading practice (due to the very slight delay) but it should still work relatively the same if im not mistaken