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

"OnServerInvoke is a callback member of RemoteFunction" error? [Question solved]

Asked by 6 years ago
Edited 6 years ago

I'm making a custom chat system that uses RemoteFunctions to give a chat handler script the required values to send a chatted message, through a custom GUI, and a RemoteEvent to send the message to all players in the game. I started building it yesterday, and overall it looks good. But I get an error while connecting an event listener to the remote function saying OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available.

I'll provide full code snippets of everything used for this. A good and reasonable answer would be perfect and well appreciated. Thanks.

P.S. I know that my chat script isn't fully complete. I'm just showing you how I'm trying to send arguements to a RemoteFunction.

Local chat script (ScreenGui):

local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local chatEvent = game.Workspace.SendMessage
local sendChatInfo = game.Workspace.ChatInvoker
local chatting = false
local chatserv = game:GetService("Chat")
uis.InputBegan:Connect(function(input)
    if input.InputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.Slash then
            if not chatting then
                chatting = true
                script.Parent:CaptureFocus()
            end
        else if input.KeyCode == Enum.KeyCode.Return then
            if chatting then
                chatting = false
                local msg = script.Parent.Text
                sendChatInfo:InvokeServer(plr, msg)
                script.Parent:ReleaseFocus()
            end
        end
        end
    end
end)

Custom Chat Handler (global script):

local SendMessageEvent = game.Workspace.SendMessage
local ChatInvoker = game.Workspace.ChatInvoker
ChatInvoker.OnServerInvoke:Connect(function(plr, msg)
    game.Chat:FilterStringAsync(msg)
    SendMessageEvent:FireAllClients(plr, msg)
end)

Remember; the error is coming from the chat handler that tries to add an event listener to a RemoteFunction at line 3 of the chat handler. There's nothing else conflicting.

Any assistance to help me build an accurate custom chat system is also acceptable.

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

your setting OnServerInvoke as a event, not a callback. also your not returning any sort of value, use a RemoteEvent instead.

correct syntax:

local SendMessageEvent = game.Workspace.SendMessage
local ChatInvoker = game.Workspace.ChatInvoker

ChatInvoker.OnServerInvoke = function(plr, msg)
    game.Chat:FilterStringAsync(msg)
    SendMessageEvent:FireAllClients(plr, msg)
end)

remote events and functions

since you dont seem to know the difference between and remote function and event im gonna explain the general idea. RemoteFunctions are for returning a value such as string, int, boolean values etc. RemoteEvents are for communicating to the client or server to do a task which the side the caller or invoker is on cannot do.

--firing and invoking the server

RemoteEvent:FireServer()

print(RemoteFunction:InvokeServer()) -- prints "hello"

then listen for them

--listening 

RemoteEvent.OnServerEvent:Connect(function(player)
    print("hello") -- prints "hello"
end)

RemoteFunction.OnServerInvoke = function(player)
    return "hello" -- returns the string value "hello"
end
Ad

Answer this question