How can I get the player's mouse on the server side?

I’m working on a script, and I don’t know how to get the player’s mouse in a server script. GetMouse() only works on the client, anyone know how to do this?

local rs = game:GetService("RunService")
local seat = game.Workspace.VehicleSeat
local player
local gun = workspace.Gun

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	player = game.Players:FindFirstChild(seat.Occupant.Parent.Name)
	print(player.Name)
end)

while true do rs.Stepped:Wait()
	local gunPos = gun.Position
	
	local mousePos = nil --Need mouse
	
	gun.CFrame = CFrame.new(rootPos, Vector3.new(mousePos.X, mousePos.Y, mousePos.Z))
end

ever heard of a remote event? (char limit)

1 Like

I know but im trying to keep it into 1 script for this system

You would have to send the information you want from the player’s mouse through a RemoteEvent to the server; you can’t get the mouse from the server side


That’s not going to work

1 Like

it takes like one line to use a remote event thou

1 Like

This could potentailly work, some events do return the mouse object.

Example here

But i’d just use a remote event,. but I mean if you wanna make it painful for yourself well…

1 Like

Alright, i guess i will just use a remote event, thanks for your suggestions

i dont know if you already found it out, but know that when you do a loop with 0 seconds delay with wait() of sending informations with remote event, your roblox studio will crash when you test it, cuz its laggy to use a remote event, and its worse when you like spawm it in loop.

i dont know what you should do instead, but remote looping remote event will not work.

If you’re going to loop remotes, you should be using UnreliableRemoteEvents. RemoteEvents aren’t laggy, it depends on how you’re using them

1 Like

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