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

How do I get mouse position from Local Script to Server Script? [ANSWERED]

Asked by 7 years ago
Edited 7 years ago

I'm trying to make when ever I press 'F' , there will be a brick spawned to the mouse position (vector 3)

Using Local Script , I created this

01local Player = game.Players.LocalPlayer
02local Mouse = Player:GetMouse()
03 
04Mouse.KeyDown:connect(function(key)
05    if key == "f" then
06 
07    local Part = Instance.new("Part",game.Workspace)
08    Part.Position = Mouse.Hit.p
09 
10    end
11end)

it works absolutely perfect. Here's the problem , I want my game to be Filter Enabled. So now, when I press 'F' , the part would be created in workspace but not at my mouse position. I tried using the 'RemoteEvent' and 'RemoteFunction'. But it wouldn't work :(

How do I get a 'Vector 3' value to my Server script?

0
remote events, add your remote event try scripts here User#20388 0 — 7y
0
I tried remote events.The thing is , I couldn't transfer a VALUE from local script to server script. I can't transfer a Vector3 value from local script to serverscript (which are trying to read the vector3) Danielkaya 58 — 7y
0
You can transfer a value, I did the same thing with the mouseposition for a building system User#20388 0 — 7y
0
OMG REALLY?! I'm trying to make a building system!! everything works fine with mine except when I turned on the Filter , I would greatly appreciate you if you share the way you transfer the value! :D Danielkaya 58 — 7y
View all comments (3 more)
0
Won't be easy as I lost the tools (cause of a studio crash), but you can transfer it using remotes like this? remote:FireServer(mouse.Hit.p) User#20388 0 — 7y
0
gonna try it :D Danielkaya 58 — 7y
0
OH MY GOD! IT WORKED! THANK YOU <3 Danielkaya 58 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

The Solution

Use Remote Event.

Local Script -

1local Player = Game.players.LocalPlayers
2local Mouse = Player:GetMouse()
3local PositionEvent = script.Parent:WaitForChild("PositionEvent")
4 
5PositionEvent:FireServer(Mouse.hit.p)  ------// Sending the Mouse.hit.p to ServerScript

Server Script -

1script.PositionEvent.OnServerEvent:connect(function(plr,Pos)   ------// Plr is Player and the Pos is the recieved value from localscript.
2 
3Part.Position = Pos
4 
5end)
Ad

Answer this question