I have a localscript thats gives me a players mouse coordinates but I want to be able to give that information to the server using remotevents or functions.
Best way to get a players mouse x,y,z?
You have a local script that gives you the mouse coordinates.
You are right. You will use remote events, in this case, to send the coordinates to the server. (Note you cannot send the mouse directly, you have to send the position instead)
Simply create a Script
(Not a LocalScript
) in ServerScriptService
and create a remote event that will have it's OnServerEvent
signal handled by that script.
Inside the LocalScript
you will :FireServer
with the mouse's position and the server will retrieve it.
--// LocalScript local players = game:GetService("Players") local client = players.LocalPlayer local mouse = client:GetMouse() local remoteEvent = ... --// define reference to your remote event remoteEvent:FireServer(mouse.Hit.Position) --// send the server the position
--// Server Script local remoteEvent = ... --// define reference to your remote event local function handlePosition(player, position) --// player who fired is automatically passed. print(player.Name, "'s mouse position is: ", position) end remoteEvent.OnServerEvent:Connect(handlePosition)
https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events