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.
-- 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
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 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
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.