Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ChatMakeSystemMessage math.random from table messages everything from table?

I'm trying to make an automatic chat system that the server makes. Every 7 minutes, the server sided script picks a phrase from a table called Texts and the server will be ready to bring that phrase to the client side. But when the client receives that information, it displays everything that was inside the table instead of picking one of the phrases. What am i doing wrong?

Server-Sided:

local SendMessage = game.ReplicatedStorage:WaitForChild("SendMessage")

Texts = {
"[Info]: Remember to Leave a Like and Favorite on the game!";
"[Info]: Check out the Store for useful Products and Passes!";
"[Tip]: You can collect Gems by searching all over the map!";
"[Info]: There is a hidden treasure chest in the map and it will reveal a code!";
"[Tip]: You can customize your gaming preference in the settings button!"
}

while true do
	--wait(420)
wait(420)
	for _, text in ipairs(Texts) do
	SendMessage:FireAllClients({
		Text = Texts[math.random(1,#Texts)];
		Font = Enum.Font.SourceSansBold;
		Color = Color3.fromRGB(255, 255, 0);
		FontSize = Enum.FontSize.Size96;	
		})
	end
end

Client-Sided:

local SendMessage = game.ReplicatedStorage:WaitForChild("SendMessage")

SendMessage.OnClientEvent:Connect(function(chatProperties)
	game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",chatProperties)
end)

1 comment

0

You are looping through all of the strings in the table with the ipairs iterator. What do you expect?

1 answer

✓ Accepted answer

Your script is set up to where every 420 seconds you go through the table the number of times that is equivalent to the amount of strings in your table. To fix this, simply take the for _, v loop out of the script.

Hope I helped!

-Cmgtotalyawesome

1 comment

0

I just figured out how to fix it myself, but thanks for the help.

This discussion is preserved as it was. New answers, comments, and votes are closed.