Hi, im trying to make system message when game staff join server and its not working script:
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
local Players = game:GetService("Players")
local StaffMembers = {1109559347, 1}
local function SendSystemMessageToAllSpeakers(msg, channel)
for _, v in pairs(ChatService:GetSpeakers()) do
v:SendSystemMessage(msg, channel)
end
end
local function PlayerAdded(plr)
if table.find(StaffMembers, plr.UserId) then
print("Work")
local formatStr = string.format("%s joined the game", plr.Name)
SendSystemMessageToAllSpeakers(formatStr, "All")
end
end
for _, v in pairs(Players:GetPlayers()) do PlayerAdded(v) end --because the chat system takes a moment to load, a player may enter the game before it's fully loaded. We'll iterate over each player currently in the game
Players.PlayerAdded:Connect(PlayerAdded)
Error: ServerScriptService.Script:6: attempt to call a nil value