Message from a non-player speaker only sends about 60% of the time

:wave:

I’m currently working with the chat modules and I am having an issue where the non-player speaker only sends a message to the player sometimes (about 60% of the time).

Script:

local serverScriptService = game:GetService('ServerScriptService')
local players = game:GetService('Players')
local runService = game:GetService('RunService')
local replicatedStorage = game:GetService('ReplicatedStorage')
local localizationService = game:GetService('LocalizationService')

local remotes = replicatedStorage:WaitForChild('Remotes')

local chatCommand = remotes:WaitForChild('ChatCommand')

local serverModules = serverScriptService:WaitForChild('ServerModules')

local commandModule = require(serverModules:WaitForChild('CommandModule'))

local chatServiceRunner, chatService, speaker, speakerObject, channel

coroutine.wrap(function()
	chatServiceRunner = serverScriptService:WaitForChild('ChatServiceRunner')

	chatService = require(chatServiceRunner:WaitForChild('ChatService'))
	speaker = require(chatServiceRunner:WaitForChild('Speaker'))

	speakerObject = chatService:AddSpeaker('Server Bot')

	channel = chatService:GetChannel('All')
	channel.Joinable = true
	channel.AutoJoin = true

	speakerObject:JoinChannel('All')
	speakerObject:SetExtraData('NameColor', Color3.fromRGB(255, 120, 120))
	speakerObject:SetExtraData('ChatColor', Color3.fromRGB(255, 195, 195))
end)()

local function sendMessage(goal, message)
	repeat runService.Heartbeat:Wait() until chatService
	local goalSpeaker
	repeat 
		goalSpeaker = chatService:GetSpeaker(goal.Name) 
		runService.Heartbeat:Wait()
	until goalSpeaker
	goalSpeaker:SendMessage(message, 'All', 'Server Bot')
end

chatCommand.OnServerEvent:Connect(function(player, query)
	local commandData = commandModule:GetCommand(query)
	local permission = commandModule:GetPermission(player)
	if commandData then
		if permission >= commandData.Permission then
			sendMessage(player, commandData.FormatFunction(player, commandData.Response))
		else
			sendMessage(player, 'You don\'t have permission to run this command!')
		end
	else
		sendMessage(player, 'Unknown command!')
	end
end)

players.PlayerAdded:Connect(function(player)
	local translator = localizationService:GetTranslatorForPlayer(player)
	sendMessage(player, translator:Translate(game, 'Hey %s!'):format(player.Name))
end)

Success rates:
Attempt 1: message not sent
Attempt 2: message sent
Attempt 3: message sent
Attempt 4: message sent
Attempt 5: message not sent
Attempt 6: message sent
Attempt 7: message not sent
Attempt 8: message not sent
Attempt 9: message sent
Attempt 10: message sent