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

How to get player mouse position without localscript?

I'm trying to get the user to place parts where ever the mouse is positioned. I'm using remote functions. I have a localscript in the tool the user uses. Then a script in serverscriptservice. Script in SSS

function placebrick()
	local part Instance.new("Part", game.Workspace)
end

game.ReplicatedStorage.Events.RemoteFunction.OnServerInvoke = placebrick

Localscript in tool

script.Parent.Activated:Connect(function()	
	game.ReplicatedStorage.Events.RemoteFunction:InvokeServer()
end)

Help please?

2 answers

✓ Accepted answer

You cannot access the mouse directly from the server. Instead, you need to send it the data from the client across your RemoteFunction:

local mouse = game.Players.LocalPlayer:GetMouse()
script.Parent.Activated:Connect(function()  
	game.ReplicatedStorage.Events.RemoteFunction:InvokeServer(mouse.Hit.p) -- mouse position
end)

In the server:

function placebrick(player, mousePosition)
	local part = Instance.new("Part", game.Workspace)
	part.Position = mousePosition
end

game.ReplicatedStorage.Events.RemoteFunction.OnServerInvoke = placebrick

1 comment

0

... what you do is invoke from the server to the client, not the other way around.

You have to get the mouse position in the LocalScript and send it as a parameter of the RemoteFunction, then get it on the server and set the part position to it.

1 comment

0

Yes It worked thanks.

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