How would I do this?
1 | --LocalScript- |
2 | --Gets Mouse |
3 | --Sends Mouse Position |
4 |
5 | --ServerScript- |
6 | --Recieves Mouse Position |
7 | --Uses it for blah blah blah. |
This is what I tried but It didnt work.
01 | -LocalScript- |
02 |
03 |
04 | Remote = game:GetService( 'ReplicatedStorage' ):WaitForChild( 'RemoteFolder' ):WaitForChild( 'RemoteFunction' ) |
05 | local Player = game.Players.LocalPlayer |
06 |
07 | mouse = Player:GetMouse() |
08 | MousePosition = mouse.Hit.p |
09 |
10 | Remote:InvokeServer(MousePosition) |
11 |
12 | -ServerScript- |
13 | Remote = game:GetService( 'ReplicatedStorage' ):WaitForChild( 'RemoteFolder' ):WaitForChild( 'RemoteFunction' ) |
14 |
15 | Remote.OnServerInvoke = function (player, MousePosition) |
16 | a = Instance.new( 'Part' ) |
17 | a.Position = MousePosition |
18 | end |
1 | local mouse = game.Players.LocalPlayer:GetMouse() |
2 |
3 | for ex: |
4 | local part = Instance.new( "Part" , workspace) -- makes a part in the workspace |
5 | part.Position = mouse.Hit.p --spawns a part where the player's mouse is |
Please answer my question if it worked, or comment if any error's.
This is in the ServerScript, you can just Fire the Server in the localscript, and make the ServerScript do what you need.
For this, you don't want to use a remotefunction
and it will yield your localscript until the server returns a value, something you don't need in this case. Instead use a remoteevent
, which only sends data 1 way.
localscript:
1 | Remote = game:GetService( 'ReplicatedStorage' ):WaitForChild( 'RemoteFolder' ):WaitForChild( 'RemoteFunction' ) |
2 | local Player = game.Players.LocalPlayer |
3 |
4 | mouse = Player:GetMouse() |
5 | MousePosition = mouse.Hit.p |
6 |
7 | Remote:FireServer(MousePosition) |
Server:
1 | Remote = game:GetService( 'ReplicatedStorage' ):WaitForChild( 'RemoteFolder' ):WaitForChild( 'RemoteFunction' ) |
2 |
3 | Remote.OnServerEvent:Connect( function (player,position) |
4 | a = Instance.new( 'Part' ) |
5 | a.Position = MousePosition |
6 | a.Parent = workspace |
7 | end ) |
Also you forgot to parent the part to the workspace, otherwise it will have a parent of "nil" and never show.
Hope this helped! If it did, please accept the answer