Is there a way to get the mouse position in a ServerScript?

Greetings developers,

Is there a way to get a player’s mouse position from a ServerScript without a RemoteEvent?

1 Like

No, and it works be subject to input lag. You need to divide responsibilities properly between the client and the server.

2 Likes

What is your purpose of getting the mouse position from a server script? If you’re making a gun tool, you can make a remote event with a parameter for Mouse.Hit that is called through a local script and listened by the server script to shoot a bullet.

1 Like

I’m using it for a plane’s turning

1 Like

Maybe you could set the plane’s network owner to the player and control it locally?

Im pretty sure you have no way of getting mouse inputs without using local scripts or any third party tools. Im afraid events are the only real practical solution to this

Wouldn’t that exhaust the remoteevent for changing the position for other players though?

You can get the mouse on client and then fire a remote event with the position of the mouse.

Sadly, there is no any other way to get the mouse on the server…

You could try this in a Local Script and Put a Remote Event in the ReplicatedStorage

local Mouse = game.Players.LocalPlayer:GetMouse()
game:GetService("ReplicatedStorage").YourRemoteEventNameHere:FireServer(Mouse.Position)

And in your Server Script Get the informations

game:GetService("ReplicatedStorage").YourRemoteEventNameHere.OnServerEvent:Connect(function(Client, MousePosition)
    -- You Got the Mouse Position of the Player
end)
1 Like

Not if you limit it. I believe you can get away with firing it once every second to be honest. If you tween the previous position with the new position (on the client, of course) you can still obtain a fairly smooth experienced. :slight_smile:

1 Like

you dont need to fire the remote event fastly and thats not how it works.

network owner is the BasePart’s physics handler. Any movements the BasePart makes, is handled by the network owner. The network owner could either be the server, or one of the players.

So let me explain how it works

when we’re trying to ride the plane, you could fire/invoke the remote event/remote function to set the plane’s network owner to the player Once (make sure the object/model is not anchored or welded to anchored parts),

Then, You could control the object locally and smoothly.

and don’t forget that network owner is exploitable and you have to make it secure by yourself

code example:

local:

function rideplane(planeRootPart)
	local setnetworkowner = game.ReplicatedStorage.RemoteFunction:InvokeServer(planeRootPart)
	
	if setnetworkowner then
		-- do things for ex: control the plane and blab lab alb al ba
	end
end

server:

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player, planerootpart)
	if [[check the plane]] then
		planerootpart:SetNetworkOwner(player)
		
		return true
	else
		return false
	end
end

I hope you understand and sorry if there is something wrong in my explanation.

1 Like