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

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

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?

7 comments

0

remote events, add your remote event try scripts here

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)

0

You can transfer a value, I did the same thing with the mouseposition for a building system

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

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)

0

gonna try it :D

0

OH MY GOD! IT WORKED! THANK YOU <3

1 answer

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)

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