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

Why is my remote function returning nil?

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.

2 comments

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.

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.

2 answers

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!

2 comments

0

Hi, sorry I should have specified but that is unrelated to the problem, I shouldn't have included it.

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.

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

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