Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

3 comments

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.

0

You can simply send the mouse.Hit.p which is a Vector3 and not an instance.

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.

2 answers

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.

2 comments

0

But I need to send the that 'mouse.Hit.p' to the ServerScript via RemoteFunction. I will try ot answer your question though.

0

Ohh via RemoteFunction, i don't know alot about RemoteFunctions.If i find anything i'll let you know

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

1 comment

0

MousePosition ?

This discussion is preserved as it was. New answers, comments, and votes are closed.