What's not working with my remote function?

So I am experimenting around on a shop system, and I am using a sample int value to see how remote functions basically work. This is what I got so far:

Local Script:

local remoteFunction = game.ReplicatedStorage.ShopFunction

script.Parent.MouseButton1Click:Connect(function()
	remoteFunction:InvokeServer()
end)

remoteFunction.OnClientInvoke = function(cash)
	print(cash)
end

Server Script

local remoteFunction = game.ReplicatedStorage.ShopFunction

remoteFunction.OnServerInvoke = function()
	remoteFunction:InvokeClient(game.Players.LocalPlayer, game.ServerStorage.Cash.Value)
end

I am getting thrown the following error:
11:36:32.575 Argument 1 missing or nil - Client - LocalScript:3

Any help would be appreciated! I am unsure where I’m wrong.

OnServerInvoke’s first parameter is always the player who invoked the function, similar to OnServerEvent, so change your OnServerInvoke Code to this

remoteFunction.OnServerInvoke = function(player)
	remoteFunction:InvokeClient(player, game.ServerStorage.Cash.Value)
end

Because as well LocalPlayer does not work in workspace.

And from a design stand point, you really shouldn’t use InvokeClient ever due to exploiters be able to put a very long wait by creating a new OnClientInvoke and practically yield the server because RemoteFunctions yield the script they’re invoked from until they’re given a return/response

1 Like