Passing Value From Local to Server

So the issue is I have a Vector3 value that I get from a local script that I need to get to a server side script but I do not know how to do this. Any help is appreciated.

3 Likes

Here i hope this will help you:

Local script:

game.Workspace.RemoteEvent:FireServer(Vector3.new(1,1,1))

Server script:

game.Workspace.RemoteEvent.OnServerEvent:Connect(function(plr, Vector3Value)
     print(Vector3Value)
end)

You can use a RemoteEvent. Take a look here: Custom Events and Callbacks | Documentation - Roblox Creator Hub

1 Like

Okay so now I’m kinda getting more confused, I think I need to go a little more in depth on what I’m trying to do. So the 1st Local Script grabs a Vector3 from a mouse click and I need to use that Vector3 and make an NPC move to it by using a 2nd Local Script inside of the NPC that moves it to the point.

So it’s not local to server then? Your title says “Passing Value From Local to Server,” but now you’re saying from a Localscript to another Localscript.

I take it that in your 1st Localscript you’re getting a Vector3 value when the player clicks something, then you want to send it to your 2nd Localscript to use in calculations for pathfinding/humanoid movement?

Sorry for taking so long… I was tryna figure things out and I think I got it. I have the 1st Local Script fire the event -

image

But I don’t know how to access the Waypoint.Position within the server script -

image

You can do this:

MTEvent.OnServerEvent:Connect(player, Pos)
    -- Whatever you need to do
end)

Edit: Also, the reason you need player in the first parameters is because RemoteEvents on the server-side always automatically place the client (player) being fired to/from in the first parameter.

1 Like

Okay thanks a lot! It sends the value now but I do have another question not to do with this topic if you could still help me. I have the NPC’s script set to move to the waypoint after the value is changed but it doesn’t budge.

(the local script inside of the NPC)
image

(the NPC’s contents)
image

1 Like

Make a value in _G and set it to the vector3, then access it from the other script

OP wants a value passed from a local script to a server script which means you cannot use _G. _G only works with the same script types.

I am not sure what you mean by that could you elaborate a little?

He wants to send a value from localscript to localscript

image
Then he needs to change the title

Make a variable in _G, and access it from the other script

_G.moveTo = Vector3.new(0,0,0)

then from the other localscript:

local position = _G.moveTo
humanoid:MoveTo(position)

Anyways,

Global variables are a bad practice in Lua so you should use a BindableEvent to pass information from one script to another. BindableEvents work just like remote events & functions but with a different syntax.

Oh I hadn’t explained… I have the value and everything in a Vector3 located in Workspace - image
Just the .Changed isn’t firing at all -
image

Try placing a print() inside of your Move() function, at let us know if it works or not. And, is Waypoint a NumValue or IntValue? If that is the case, I don’t believe your Human:MoveTo will work, as the first parameter requires a Vector3 value.

I already tried a Print() and it did not run, and I am using a Vector3 Value.
image

You do use a local script in the NPC to use the MoveTo() right?

Hmm, are you sure that it’s changing in value? Double check that for the sake of it if you may.

Try this instead and see what happens:

Waypoint:GetPropertyChangedSignal("Value"):Connect(Move)

Edit:

Yes, I believe it should work from a LocalScript.