Mouse nil on both server & client

I need to get the players mouse on server, tried both player:GetMouse() on server and on client but both return a nil, I use a remote to send the mouse to the server

You cannot use the player mouse on the server.

1 Like

What am I supposed to do to get where it’s looking at then? Not target

You can’t just send player:GetMouse() via a remote event to the server, try sending it as

local mouse=game.Players.LocalPlayer:GetMouse()

event:FireServer({Hit=mouse.Hit,Target=mouse.Target})

then on the server just do received.Hit or received.Target

I don’t want it’s target,I need to detect mouse movement on the servers side

You can just send the mouse.Hit to the server in a loop and check if the new received one is different from the last one using variables!

Just fire the RemoteEvent every time the mouse is moved:

mouse.Move:Connect(function()
    RemoteEvent:FireServer()
end)

Although, this is not recommended.

You can only send the properties of the mouse from the client to the server, not the mouse object itself.

local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local mouse = player:GetMouse()
local storage = game:GetService("ReplicatedStorage")
local remote = storage:WaitForChild("RemoteEvent")

mouse.Move:Connect(function() --event triggered everytime the local players mouse is moved
	remote:FireServer(mouse.Hit.p) --fires the server and send the current position of the mouse (as a Vector3 value) to the server
end)

https://developer.roblox.com/en-us/api-reference/event/Mouse/Move

I believe you were referring to “Move”.

I would avoid using a while true do/while task.wait() do loop to achieve this since you’ll end up firing the server even if nothing about the mouse has changed since the server was last fired.