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

I am getting the same error with a RemoteFunction Please help me understand it?

I have been getting this error with a RemoteFunction, I am sending back a table of Player Usernames when It gets called for a ServerInvoke on my Client.

OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available

This is an example of my code:

Server:

local WinnerTable = game:GetService("ReplicatedStorage"):WaitForChild("QEvents"):WaitForChild("Winner"):WaitForChild("WinnerTable")
local winners = {"Roblox"}

WinnerTable.OnServerInvoke:Connect(function()
	return winners 
end)

Client:

local WinnerTable = game:GetService("ReplicatedStorage"):WaitForChild("QEvents"):WaitForChild("Winner"):WaitForChild("WinnerTable")
local winners = WinnerTable:InvokeServer()
	for i,v in ipairs(winners) do
		winners = winners + 1
	end

3 comments

0

I'm pretty sure you're not supposed to call back the table that way. you should do return table at the end of your serverscript. It's just like how you would return certain values in a function

0

Can you give an example as an answer in a codeblock?

0

OnServerInvoke and OnClientInvoke are callback functions, not events, so they can't be connected. you simply set them.

2 answers

✓ Accepted answer

Remote functions aren't the same as remote events.

This is the place where you made the mistake

WinnerTable.OnServerInvoke:Connect(function()

end)

Instead you should use this

function WinnerTable.OnServerInvoke()  

end)

2 comments

0

Thanks!

0

np :)

Here's a very simple one it will Damage the player by 10 damage upon spawning:

local script

RF = game.Lighting.RemoteFunction
local player = game.Players.LocalPlayer
local char = player.CharacterAdded:wait()
local result = RF:InvokeServer(char.Humanoid)
char.Humanoid:TakeDamage(result)

ServerScript

RF = game.Lighting.RemoteFunction
RF.OnServerInvoke = function(Player,Received) --First Info is always the Player
	print(Received) 	-- Shows that I've sent over a value from the client side
	Damage = 10
	return Damage
end

RF is the remotefunction's remote, that I've placed inside lighting.

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