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

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

Asked by 4 years ago

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.

0
ok why u are making a custom filter? Ariya1234gamer 15 — 4y
0
its for my custom chat NinjaTeam_NT 2 — 4y
0
ok Ariya1234gamer 15 — 4y
0
u can send the error output type? Ariya1234gamer 15 — 4y
0
oh i see the error ion the title srry Ariya1234gamer 15 — 4y

2 answers

Log in to vote
-1
Answered by 4 years ago

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

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)

0
ima go test it on a server NinjaTeam_NT 2 — 4y
0
my awnser is helptul or u found it? Ariya1234gamer 15 — 4y
0
the awnser Ariya1234gamer 15 — 4y
0
moving it to the server worked NinjaTeam_NT 2 — 4y
View all comments (9 more)
0
oh so if u can accept my awsner Ariya1234gamer 15 — 4y
0
it filters :D NinjaTeam_NT 2 — 4y
0
i hope u finish ur game and u get 1M views 999K from other players 1 view from me XD Ariya1234gamer 15 — 4y
0
i'm planning to make an adventure/survival game NinjaTeam_NT 2 — 4y
0
good me to i am making a survival/Adventure/fps game Ariya1234gamer 15 — 4y
0
k NinjaTeam_NT 2 — 4y
0
also u can use this for your game (if you want a custom chat) NinjaTeam_NT 2 — 4y
0
oh no thx i can make one Ariya1234gamer 15 — 4y
0
k NinjaTeam_NT 2 — 4y

Answer this question