NPC Chat Sends Same Message

Hello Developers.

I’m having trouble with my NPC Referee Chatting. When there’s only 1 player on the team the referee is speaking too everything works just fine. But when I put multiple people on the team, depending on how many people are on that team it would send the same message that many times. It’s my first time working with ChatService so I don’t really understand whats going on or why this is happening. Please Help as soon as you can.

Thank you.

Picture:

Code:

-- Functions {Chat {For Referee}} --
local function ChatMsg(Chatter,Message)
	task.wait(1.5)
	-- Call {Chat Function} --
	if RefereeCanChat == true then
		ChatService:Chat(Chatter,Message)
	end
end
----
elseif SentEvent[1] == 'CoinToss' then
		-- Check {LocalPlr's Team} --
		if LocalPlr.Team == GameConfiguration.AwayTeam.Value then
			-- Start {CoinToss} --
			ChatMsg(GameSpaceFolder.Chains.Referees:WaitForChild('Referee5').Head,"Welcome ladies & gentlemen to today's game.")
			ChatMsg(GameSpaceFolder.Chains.Referees:WaitForChild('Referee5').Head,"Visiting team, what is your call.")
			task.wait(0.2)
			CoinTossSelection(LocalPlr)
			----
			
			-- Get {Toss Result} --
			repeat task.wait() until SelectedCoinSide ~= nil
			local Landed = 'Heads'
			if math.random(1,2) == 2 then
				-- Update {Landed} --
				Landed = 'Tails'
			end
			----

			-- Check {SentEvent[2]} --
			if Landed == SelectedCoinSide then
				GameConfiguration:SetAttribute('WonToss',GameConfiguration.AwayTeam.Value.Name)
			else
				GameConfiguration:SetAttribute('WonToss',GameConfiguration.HomeTeam.Value.Name)
			end
			-- Chat {Referee} --
			ChatMsg(GameSpaceFolder.Chains.Referees:WaitForChild('Referee5').Head,SelectedCoinSide .. ' was the call.')
			ChatMsg(GameSpaceFolder.Chains.Referees:WaitForChild('Referee5').Head,'The result is ' .. Landed .. '.')
			ChatMsg(GameSpaceFolder.Chains.Referees:WaitForChild('Referee5').Head,GameConfiguration:GetAttribute('WonToss') .. ' has won the toss.')
			ChatMsg(GameSpaceFolder.Chains.Referees:WaitForChild('Referee5').Head,GameConfiguration:GetAttribute('WonToss') .. ' do you elect to receive or kickoff the ball.')
			NeededRemotesFolder.GameUpdate:FireAllClients({'CoinToss'})
		end
5 Likes

Two questions, is the second code you sent on a loop?

and is this

ChatMsg(GameSpaceFolder.Chains.Referees:WaitForChild(‘Referee5’).Head,“Welcome ladies & gentlemen to today’s game.”)

also repeated?

2 Likes

Nope it doesn’t get repeated (char 2.0)

1 Like

It’s like depending on how many people are on that team. It would send the message for every single one of them and on the server everyone see’s it I want to make it so that it only sends 1 that everyone can see. Not multiple

Alright, I see a possible workaround here, which is making this script work serverside instead of clientside. The way you can do this is to check if there’s atleast one person on that team and then proceed with executing the code if that check passes.

I guess chatservice works the same way as animations, it plays for everyone even if it’s executed on only one client (Or I might just be saying nothing useful, who knows)

I tried making it do that it still will send multiple messages

1 Like

I think your issue is that your putting else instead of elseif, try this.

if Landed == SelectedCoinSide then
				GameConfiguration:SetAttribute('WonToss',GameConfiguration.AwayTeam.Value.Name)
			elseif Landed ~= SelectedCoinSide then
				GameConfiguration:SetAttribute('WonToss',GameConfiguration.HomeTeam.Value.Name)
			end
2 Likes

Ill try and see how it goes {char 2.0}

1 Like

It still multi chats it it didn’t work thank you though

1 Like

Hm, thats weird, im not a scripter lol but i know a bit. Are your scripts server sided or client sided?

Its all server based but some of the things get sent from a client back too the server

1 Like

But all the chatting is done off the server

1 Like

Are the contestants sent to the server?

1 Like

To start, i believe the camera should be a server script.

Can you send any other screenshots of the server script?

1 Like

Alright, i honestly currently have no ideas on what the error is. For me, its quite late. So ill try and resolve it in the morning if you haven’t found the error yet. Just message me.

Good luck!

1 Like

Alright, Thank you for your help

1 Like