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

How to get player mouse position without localscript?

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago

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
0
... what you do is invoke from the server to the client, not the other way around. Elixcore 1337 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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.

0
Yes It worked thanks. User#29320 0 — 5y

Answer this question