Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

ChatMakeSystemMessage math.random from table messages everything from table?

Asked by 5 years ago

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)
0
You are looping through all of the strings in the table with the ipairs iterator. What do you expect? User#25115 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

0
I just figured out how to fix it myself, but thanks for the help. BrawlBattle 15 — 5y
Ad

Answer this question