RemoteFunction Issue

Hey so im trying to do things with remotefunctions,

Im trying to make it so the server side will fire a remotefunction and the remotefunction which is on the client side will return a players mouse lookvector, However it isn’t working very well for me and I have no idea what the issue is because it just says argument 1 missing or nil
BV = Body Velocity

(Also if it wasn’t clear this is my first time messing with remotefunctions so I got no idea what I’m doing)
–Client

tool.RemoteFunction.OnClientInvoke = function(velocity)
	local Speed2 = game.Players.LocalPlayer:GetMouse().Hit.LookVector
	return Speed2
end

—Server

	local NewSpeed = tool.RemoteFunction:InvokeClient(Velocity)
	print(NewSpeed)
	Velocity = NewSpeed*113
	return Velocity 
end

Maybe you should pass a player object when firing as the first argument

I’m not that good with RemoteFunctions but it is probably because of these reasons:

1: The RemoteFunction is not in ReplicatedStorage (this may not be an issue but usually it’s a good practice)

2: You may need to get a dummy field
In simpler terms, to get fields you need a dummy field when reciving values

-- Correct:
local Return = ReplicatedStorage.func.OnClientInvoke:Connect(function(dummy, velocity)

-- Incorrect:
local Return = ReplicatedStorage.func.OnClientInvoke:Connect(function(velocity)

Anyway, sorry for that long write up, Hope this helps!

You need to pass a player instance as the first argument to InvokeClient() in order to specify which client to invoke.

This is similar to how FireClient() of a RemoteEvent instance also requires its first argument to be a player instance indicating which client to fire.

2 Likes

I passed the player as a first argument, still get argument 1 missing or nil

Tried, did not work

char limitttttttttttttttt

are you passing the mouse from the server? you cant get the players mouse from the server

nevermind i didnt read that right :sweat_smile:

BodyVelocity is deprecated btw