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

How do I fix attempt to index nil with 'GetChatForUserAsync'?

I'm trying to make a filter for my custom chat but every time I try to filter something it throws an error.

--LocalScript that send the message to the server

local LocalPlayerName = game:GetService("Players").LocalPlayer.Name
local Rank = "(Test Rank)"
local Text = "im trying to filter this: d7sjfix8snd" --text

game:GetService("ReplicatedStorage").SendMessage:FireServer(LocalPlayerName,Rank,Text)

The script above and below work fine

--Script that receives the message

game:GetService("ReplicatedStorage").SendMessage.OnServerEvent:Connect(function(PlrWhoSent,Plr,Rank,Message)
	local TextService = game:GetService("TextService")
	local Msg = ""
	local success,err = pcall(function()
		FilteredString = TextService:FilterStringAsync(Message,PlrWhoSent.UserId)
	end)
	if err then
		warn("Failed to filter text: "..err)
		Msg = "<Failed To Filter Text>"
	else
		Msg = FilteredString
	end
	
	game:GetService("ReplicatedStorage").SendMessage:FireAllClients(Plr,Rank,Msg)
end)

This is where the error occurs

--LocalScript that receives the message

game:GetService("ReplicatedStorage").SendMessage.OnClientEvent:Connect(function(Plr,Rank,Msg)
local FilteredMessage = Msg:GetChatForUserAsync(game:GetService("Players").LocalPlayer.UserId) 
	
	--[[script.Parent.MessageReady:Fire(FilteredMessage)

	This sends it to the script that handles the messages]]

I tried looking for a solution, but i didnt find anything.

5 comments

0

ok why u are making a custom filter?

0

its for my custom chat

0

ok

0

u can send the error output type?

0

oh i see the error ion the title srry

2 answers

✓ Accepted answer

ok u putted it on server so put it back to client and dont use FireAllClients use FireClient and after that if it work u will use a for and send the message to everyone

I think i fixed it!

Server script:

--Script that receives the message

game:GetService("ReplicatedStorage").SendMessage.OnServerEvent:Connect(function(PlrWhoSent,Plr,Rank,Message)
    local TextService = game:GetService("TextService")
    local Msg = ""
    local success,err = pcall(function()
        FilteredString = TextService:FilterStringAsync(Message,PlrWhoSent.UserId)
    end)
    if err then
        warn("Failed to filter text: "..err)
        Msg = "<Failed To Filter Text>"
    else
        Msg = FilteredString
    end
	local FilteredMsg = Msg:GetChatForUserAsync(PlrWhoSent.UserId)
	game:GetService("ReplicatedStorage").SendMessage:FireAllClients(Plr,Rank,FilteredMsg)
end)

Client script:

--LocalScript that send the message to the server

local LocalPlayerName = game:GetService("Players").LocalPlayer.Name
local Rank = "(Test Rank)"
local Text = "im trying to filter this: d7sjfix8snd" --text

game:GetService("ReplicatedStorage").SendMessage:FireServer(LocalPlayerName,Rank,Text)

game:GetService("ReplicatedStorage").SendMessage.OnClientEvent:Connect(function(Plr,Rank,Msg)
warn(Msg)
end)

13 comments

0

ima go test it on a server

0

my awnser is helptul or u found it?

0

the awnser

0

moving it to the server worked

0

oh so if u can accept my awsner

0

it filters :D

0

i hope u finish ur game and u get 1M views 999K from other players 1 view from me XD

0

i'm planning to make an adventure/survival game

0

good me to i am making a survival/Adventure/fps game

0

k

0

also u can use this for your game (if you want a custom chat)

0

oh no thx i can make one

0

k

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