Issue with filtering string

My custom chat was working fine before but have this error now: Error is at msg = msg:GetChatForUserAsync(v.UserId) (“Attempt to call a nil value”) Relevant snippet of script below:

local msg = textService:FilterStringAsync(text, player.UserId, 1)

for _,v in pairs (game:GetService("Players"):GetChildren()) do
    msg = msg:GetChatForUserAsync(v.UserId) 
        remote:FireClient(v, player, msg)
end
1 Like

I think you should use :GetPlayers() since :GetChildren() gets everything(including non-players)

The only instances in the Players game service should be the Player instance.

The issue here is that you’re setting the variable outside the scope (TextFilterResult) to the output you get from msg:GetChatForUserAsync(v.UserId) (a string), so when it iterates to the second player,
it’ll attempt to call [string]:GetChatForUserAsync(v.UserId).
That means it’ll output that error.

The fix would be quite simply to put local in front of msg = msg:GetChatForUserAsync(v.UserId), as that makes it so that the variable is limited to that scope.

1 Like