Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
uhTeddy 101
6 years ago
Edited 6 years ago

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
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 lesliesoon 86 — 6y
0
Can you give an example as an answer in a codeblock? uhTeddy 101 — 6y
0
OnServerInvoke and OnClientInvoke are callback functions, not events, so they can't be connected. you simply set them. cabbler 1942 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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)
0
Thanks! uhTeddy 101 — 6y
0
np :) User#20388 0 — 6y
Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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.

Answer this question