New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How to check if player recieves a new chat message with a local script?

Asked by 14 days ago

How do I check for when a player recieves a new chat message from another player?

1 answer

Log in to vote
1
Answered by
Nanomatics 1107 Moderation Voter
14 days ago

You can use a Serverscript and Localscript and communicate through a RemoteEvent.

The serverscript will listen to all players when they chat and make sure that the message is going to show up for the player, then communicate to this player's client script.

Then you can do whatever you want to happen through that localscript

ServerScript

local ReplicatedStorage = game:FindService("ReplicatedStorage") 
local RemoteEvent = ReplicatedStorage.Chat -- assuming you have a remoteevent called "Chat" under "ReplicatedStorage" 

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg, intendedPlr)
        if not intendedPlr or intendedPlr == player then -- check if plr is receiving a normal chat or whisper
            RemoteEvent:FireClient(player)
        end
    end)
end)

LocalScript

local ReplicatedStorage = game:FindService("ReplicatedStorage") 
local RemoteEvent = ReplicatedStorage.Chat

RemoteEvent.OnClientEvent:Connect(function()
    -- plug in what you want to happen on the client side whenever the player gets a new chat message
end)

Hope I helped, if you have any questions please let me know!

Ad

Answer this question