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 6 years ago
Edited 6 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


local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.KeyDown:connect(function(key) if key == "f" then local Part = Instance.new("Part",game.Workspace) Part.Position = Mouse.Hit.p end end)

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 — 6y
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 — 6y
0
You can transfer a value, I did the same thing with the mouseposition for a building system User#20388 0 — 6y
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 — 6y
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 — 6y
0
gonna try it :D Danielkaya 58 — 6y
0
OH MY GOD! IT WORKED! THANK YOU <3 Danielkaya 58 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

The Solution

Use Remote Event.

Local Script -

local Player = Game.players.LocalPlayers
local Mouse = Player:GetMouse()
local PositionEvent = script.Parent:WaitForChild("PositionEvent")

PositionEvent:FireServer(Mouse.hit.p)  ------// Sending the Mouse.hit.p to ServerScript

Server Script -

script.PositionEvent.OnServerEvent:connect(function(plr,Pos)   ------// Plr is Player and the Pos is the recieved value from localscript.

Part.Position = Pos

end)
Ad

Answer this question