Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to get the Mouse Position in a ServerScript using Remote Functions?

Asked by 6 years ago
Edited 6 years ago

How would I do this?

--LocalScript-
--Gets Mouse
--Sends Mouse Position

--ServerScript-
--Recieves Mouse Position
--Uses it for blah blah blah.

This is what I tried but It didnt work.

-LocalScript-


Remote = game:GetService('ReplicatedStorage'):WaitForChild('RemoteFolder'):WaitForChild('RemoteFunction')
local Player = game.Players.LocalPlayer

mouse = Player:GetMouse()
MousePosition = mouse.Hit.p 

Remote:InvokeServer(MousePosition)

-ServerScript-
Remote = game:GetService('ReplicatedStorage'):WaitForChild('RemoteFolder'):WaitForChild('RemoteFunction')

Remote.OnServerInvoke = function(player, MousePosition)
a = Instance.new('Part')
a.Position = MousePosition
end
1
I would ask those who are moderating to have some common sense. He has demonstrated he has a real problem and has tried to fix it and has provided code. There is no rule violation here. lukeb50 631 — 6y
0
You can simply send the mouse.Hit.p which is a Vector3 and not an instance. User#5423 17 — 6y
0
@lukeb50 Exactly why I later edited and quickly put code of what was an error in my script. I know 'a.Parent' is supposed to be workspace. I was rushing for the matter of not getting my question deleted. DeathGunner132 120 — 6y

2 answers

Log in to vote
0
Answered by
oSyM8V3N 429 Moderation Voter
6 years ago
Edited 6 years ago
local mouse = game.Players.LocalPlayer:GetMouse()

for ex:
local part = Instance.new("Part", workspace) -- makes a part in the workspace
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.

0
But I need to send the that 'mouse.Hit.p' to the ServerScript via RemoteFunction. I will try ot answer your question though. DeathGunner132 120 — 6y
0
Ohh via RemoteFunction, i don't know alot about RemoteFunctions.If i find anything i'll let you know oSyM8V3N 429 — 6y
Ad
Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
6 years ago

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:

Remote = game:GetService('ReplicatedStorage'):WaitForChild('RemoteFolder'):WaitForChild('RemoteFunction')
local Player = game.Players.LocalPlayer

mouse = Player:GetMouse()
MousePosition = mouse.Hit.p 

Remote:FireServer(MousePosition)

Server:

Remote = game:GetService('ReplicatedStorage'):WaitForChild('RemoteFolder'):WaitForChild('RemoteFunction')

Remote.OnServerEvent:Connect(function(player,position)
    a = Instance.new('Part')
    a.Position = MousePosition
    a.Parent=workspace
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

0
MousePosition ? User#5423 17 — 6y

Answer this question