Answered by
4 years ago Edited 4 years ago
The Mouse Object is becoming obsolete i would recode it using the UserInputService
But for now this is a way on how to solve the problem you're facing at the moment....
Code:
Server Script
01 | local replicatedstorage = game:GetService( "ReplicatedStorage" ) |
02 | local re = replicatedstorage:waitForChild( "RemoteEvent" , 10 ) |
05 | Button 1 Clicked = false , |
06 | Button 2 Clicked = false , |
07 | Position = Vector 2. new(), |
11 | local MouseFired = false |
12 | local function event(player,mouse) |
14 | for k,v in pairs (mouse) do |
20 | re.OnServerEvent:connect(event) |
24 | if (MouseFired = = true ) then |
27 | table.foreach(Mouse, function (a,b) |
Local script
01 | local replicatedstorage = game:GetService( "ReplicatedStorage" ) |
02 | local re = replicatedstorage:waitForChild( "RemoteEvent" , 10 ) |
04 | local player = game.Players.LocalPlayer |
05 | local mouse = player:getMouse() |
06 | local MouseWheelZeroTime = 0.01 |
09 | Button 1 Clicked = false , |
10 | Button 2 Clicked = false , |
11 | Position = Vector 2. new(), |
16 | mouse.WheelBackward:connect( function () |
19 | wait(MouseWheelZeroTime) |
24 | mouse.WheelForward:connect( function () |
27 | wait(MouseWheelZeroTime) |
32 | mouse.Button 1 Up:connect( function () |
33 | Mouse.Button 1 Clicked = false |
34 | Mouse.Target = mouse.Target |
35 | Mouse.Hit = mouse.Hit.Position |
39 | mouse.Button 1 Down:connect( function () |
40 | Mouse.Button 1 Clicked = true |
44 | mouse.Button 2 Up:connect( function () |
45 | Mouse.Button 2 Clicked = false |
49 | mouse.Button 2 Down:connect( function () |
50 | Mouse.Button 2 Clicked = true |
54 | mouse.Move:connect( function (thing) |
55 | Mouse.Position = Vector 2. new(mouse.X,mouse.Y) |
So in your Server script just remember you're working from the Mouse Table and not the Mouse
object! As you cannot pass the mouse object from a local script as you know.
So the above example is Side-stepping that problem and re-creating the Mouse object on both Client and server scripts through the use of a table in both.
The only other problem i can foresee is if many people are playing the game you may get Exceeded number of callback
Errors and scripts breaking due to the amount of data being sent.
To reduce the amount of data being sent through the Client Server Boundary I would limit the amount of calls to the server from the client. For instance if you're placing a block and wanted it to show on the screen at the mouse cursor point i would replicate or fake it in the client script and only when you place it down via Mousebutton1Click
, send the updated data to the server. And if you wanted others to see it I would only update that once per second or something.
That way it drastically reduces the amount of calls from the client.
Just some ideas
Hope this helps! :)
For reference on the UserInputService
you can check out the wiki here:
https://developer.roblox.com/en-us/api-reference/class/UserInputService