Help with a script

Hi,

I need help with a script.The script is working just fine. But I want too add on to it. How do I make it so that each phrase(string) won’t duplicate itself twice? For example.

We have 3 strings. “hi” “hello” “hey”

I don’t want it so it goes “hi” “hi” “hello” I don’t want two of the same strings together. I want them to be operate so they will never be duplicated together. If this doesn’t make sense tell me and I will try my best to make it more understandable.

script

local text = {

    "Random stuff generating";
    "Boring loading screen made just for you";
    "Your computers slow";
    "Taking up storage...";
    "Devs have hammers that boot people in the sun";
    "Tip: Dont die";

} 

while wait(2) do
    script.Parent.Text = text[math.random(1,#text)]
end

I’m not sure I understand, are you trying to say you don’t want it to choose the same thing twice?

1 Like

yes. To make it so that the same string isn’t together.

1 Like

Here’s what I would do:

local text = {

	"Random stuff generating";
	"Boring loading screen made just for you";
	"Your computers slow";
	"Taking up storage...";
	"Devs have hammers that boot people in the sun";
	"Tip: Dont die";

} 

local lastChosen = 0 -- the last item number
local chosen = 0 -- the current item number

while wait(2) do
	repeat
		chosen = math.random(1,#text)
	until chosen ~= lastChosen -- Repeats until the current item number is not equal to the last item number
	
	script.Parent.Text = text[chosen]
	lastChosen = chosen -- sets the last chosen item number to the current item number
end

I have a system similar to this in my game when choosing out gamemodes.

1 Like

Did you mean script.Parent.Text = text[chosen]?

2 Likes

Yes I did, thank you for pointing that out. I corrected it.

1 Like