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

Why is my remote function returning nil?

Asked by 3 years ago

Hi everyone, quick question.

I'm basically sending out announcements in a game to all clients, but before doing so it individually matches the player's chat filtering settings.

I do this using a remote function to filter the chat in a server script, and then return the filtered text.

Here is my code?

Server Script:

local repStore = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")

function repStore.filterMsg.OnServerInvoke(player,msg)
    local success, errorMessage = pcall(function()
        return TextService:FilterStringAsync(msg, player.UserId):GetChatForUserAsync(player.UserId)
    end)
    if not success then
        warn("Error filtering text:", msg, ":", errorMessage)
        return
    end
end

Local Script:

repStore.sendAnnouncement.OnClientEvent:Connect(function(msg,timer) --this is a remote event that is used for when an admin sends the announcement
    msg = repStore.filterMsg:InvokeServer(msg)
    print(msg)
end)

Any suggestions would be much appreciated.

0
It is probably returning 'nil' because it didn't have enough time to process the filter, I am not so sure how you should go about to fix it. Torren_Mr 334 — 3y
0
During a test I put print(msg) before and after it being filtered (obviously removed the return and made it a variable) - it worked fine and filtered it properly it just doesn't make it back to the local script. ryanaskew 50 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Okay your issue here is your listening for "OnClientEvent' you should be listening for "OnClientInvoke" with a remotefunction since OnClientEvent pertains to A remote event. See if that solves the problem!

0
Hi, sorry I should have specified but that is unrelated to the problem, I shouldn't have included it. ryanaskew 50 — 3y
0
Oops, sent comment early. As I was saying, the event is in the admin script which isn't related to this but the remote function I'm having the problem with is in the server script (first script I show). I InvokeServer in line 2 of the local script. ryanaskew 50 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Found out it was because I was returning it in the pcall function, not sure why but oh well... works now.

Answer this question