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.
✓ ANSWER ACCEPTED
Best way to get a players mouse x,y,z?
1 answer
✓ Accepted answer
Question
Best way to get a players mouse x,y,z?
Given Context
You have a local script that gives you the mouse coordinates.
Solution
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.
Example Codeblock
####LocalScript
--// 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
####ServerScript
--// 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)
Further Reading
https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thanks!