Send text from server to client using remote event

I spent way too long on this. What I need is in the title. Here is what I tried:

-- Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Chat_Event = ReplicatedStorage:WaitForChild("Chat")

Chat_Event:FireClient("Text to chat")
-- Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Chat_Event = ReplicatedStorage:WaitForChild("Chat")

local function chat(msg)
	game:GetService("ReplicatedStorage").DefaultChatSystemChatEvents.SayMessageRequest:FireServer(msg, "All")
end

Chat_Event.OnClientEvent:Connect(chat)

Basically in the server script I get this error: Unable to cast value to Object
When I searched it up I just found a post about the teleport service. How do I fix this? Also is the local script good, or I will just get another error.

1 Like
Chat_Event:FireClient(game.players:FindFirstChildWhichIsA("Player"), "Text to chat")

parameter 1 must be a player when using FireClient

The first argument should be the player receiving the event. Are you sending your message to a specific player, or all players?

Thanks for replying! I got this error: players is not a valid member of DataModel “Game”. I also tried defining players with game:GetService(“Players”)

just use fire all clients

Chat_Event:FireAllClients("Text to chat")
1 Like

Thanks! I am new to remote events, and I thought FireClient would do the same thing. My bad

1 Like

Use game.Players instead of game.players

Chat_Event:FireClient(game.Players:FindFirstChildWhichIsA("Player"), "Text to chat")
1 Like