New Player Joined Script Not Working

I asked the assistant in Roblox Studio this: “Write me a script so when you join the Roblox game, the server says in-game chat that the user has joined the server.”
It then gave me this script:

local Players = game:GetService("Players")

-- Function to announce when a player joins
local function announceJoin(player)
    -- Use the Chat service to send a message to all players in the game
    game:GetService("Chat"):BroadcastMessage(player.Name .. " has joined the game!", Enum.ChatColor.Blue)
end

-- Connect the announceJoin function to the PlayerAdded event
Players.PlayerAdded:Connect(announceJoin)

-- Iterate through all existing players and announce them (in case the script is reloaded)
for _, player in ipairs(Players:GetPlayers()) do
    announceJoin(player)
end

It put it in ServerScriptService as AnnouncePlayerJoin, I then joined the game but nothing happened. Nothing showed up in game chat, so I checked the dev console and it said:
image
If you know what is wrong with the script please let me know!

I’ve changed your announceJoin function because Chat:BroadcastMessage() is not a function that exists.

local Players = game:GetService("Players")

-- Function to announce when a player joins
local function announceJoin(player)
    -- Use the Chat service to send a message to all players in the game
    game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(player.Name .. " has joined the game!")
end

-- Connect the announceJoin function to the PlayerAdded event
Players.PlayerAdded:Connect(announceJoin)

-- Iterate through all existing players and announce them (in case the script is reloaded)
for _, player in ipairs(Players:GetPlayers()) do
    announceJoin(player)
end

I put this into the script, but still does not seem to work. Just to make sure, does this have to be a script or a localscript? Right now its just a script in serverscriptservice

Localscript, put it in StarterPlayerScripts

I have put it into a localscript and in StarterPlayerScripts. I have checked in the dev console for any errors and there are none, but noting still shows up in chat

That’s probably because the script is initialized after your player joins, try to test using team test or the multiple player sessions.

1 Like

Only got this message in chat


I also joined the game from Roblox and nothing still shows up. (I also have the game private as its a test place but I don’t know if that would make it so this would not work.)