How do I fix "ServerScriptService.ChatServiceRunner.ChatService:129: Speaker ' ' already exists!" error?

Ok, so basically I’m trying to create bots for a game and I want them to act like real players, so I thought it would be a great idea for them to be able to “chat” using the chat system.

My problem is that I am using math.random to make a fake player have a randomly selected username and a randomly selected phrase from a list of different phrases and usernames.
However, if a username gets chosen more than once, this error appears in output and the code stops functioning:

Here’s a video of the script in action:

Here’s my script:


local serverScriptService = game:GetService('ServerScriptService')
local module = require(serverScriptService:WaitForChild('ChatServiceRunner').ChatService)

local Names = {
--lists a set of usernames for the fake players
	"aloguilherme_333";
	"Boby43";
	"fhdjsakue37";
	"buckeyesboris28";
	"LBozoPlusRatio";
	"luisgamercool26";
	"yellowpairof_pants";
	"bombdotcom3328";
	"Ceaches1";
	"doggydoggydaw";
	"TheGoodGuy";
	"preppygirlygamer";
	"grrrahbaddie36322";
	"usualjeans21";
	"Limbtrscuit98432";
	"richselfishqueen";
	"slomo333"
}

local Dialogue = {
--lists a set of phrases that can be said in the chat
		"hey!";
		"this game is so rigged!";
		"lol";
		"grrrrr";
		"fire away!";
		"run!";
		"omg";
		"NOOOOO";
		"ughhh";
		"uhm";
		"hey guys!";
		"erm";
		"wow!";
		"Wheee!";
		"AHHHHHHH";
		"STOP KILLING ME";
		"Haha";
		"Hi everyone!";
		"This game is so fun";
		"We should play again sometime";
		"Lol";
		"Watch me guys";
		"I'm better than all of you";
		"I HATE THIS GAME!";
		"I'm so mad";
		"Heheheh";
		"Oh my gosh";
	    "bruh";
	    "i'm gonna leave soon";
	    "erm what the...";
	    "bruv";
	    "boo";
	    "go!";
	    "IT'S RIGHT THERE";
	    "OH EM GEE";
	    "HEY Y'ALL";
	    "SUP";
	    "wassup";
	    "yo";
	    "This game is interesting";
	    "Are there any badges in this game";
	    "airughaoidfhaldkhj";
	    "############";
	    "#######";
	    "Oh hi!";
	    "yesssssssuh";
	    "Yay";
	    "Teehee";
	    "I just got flung lol";
	    "Skill issue";
	    "It's raining tacos";
	    ";-;";
	    ":(";
	    ":)"
		
		
}
while true do
--uses math.random to choose a random name from the list of names
	local randomName = math.random(1, #Names)
	local pickedName = Names[randomName] 
	
--uses math.random to choose phrase from the list of phrases
	local randomDialogue = math.random(1, #Dialogue)
	local pickedDialogue = Dialogue[randomDialogue]

	local speaker = module:AddSpeaker(pickedName)
	speaker:JoinChannel('All')
	wait(math.random(3,15))
	speaker:SetExtraData('NameColor', Color3.new(0, 0.5, 1))
	speaker:SayMessage(pickedDialogue, 'All')
	end

I have tried looking through previous posts on dev forum and I have tried watching videos to see how to resolve this error, but I’m still stuck, so help would be greatly appreciated.

You can’t have a second speaker with the same name. Instead of running :AddSpeaker everytime you pick, have all of them already added in a table and then select from that table.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.