Random text generator not working

I did not find any errors in the output.

local words = {"If I could see you, I would give you a great big hug!";
    "You are a great person";
    "You are amazing";
    "I know you can do anythig";
    "You are super smart";
    "Tell me more"
}

script.Parent.Activated:Connect(function()
    print{words [math.random(#words)]}
    script.Parent.Text = {words[math.random(#words)]}
end)

script is meant to be to give random sentences when you click on the button.

script.Parent.Text = words[math.random(#words)]

1 Like

Hi! Here’s the fixed script:

local words = {"If I could see you, I would give you a great big hug!";
    "You are a great person";
    "You are amazing";
    "I know you can do anythig";
    "You are super smart";
    "Tell me more"
}

script.Parent.Activated:Connect(function()
    print(words[math.random(1, #words)])
    script.Parent.Text = words[math.random(1, #words)]
end)

What I fixed - you don’t need the table brackets for a string. Additionally, added the 1 argument to the math.random function, as you should have a starting value for this function.

1 Like

You don’t need a second argument for math.random(), as stated here.

When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m].

yea, but it’s a good practice imo, so you know for sure which number it starts from.

Do you also do for loops like this?

for Count = 1, #Amount, 1 do

end

Instead of

for Count = 1, #Amount do

end

Just to be sure it’s ticking up 1 at a time, even though it’s the default value. :slight_smile:

Yes, that’s actually how I do my for loops :joy: . That’s because I mostly deal with smaller values, hence the need for the increment property.

Interesting! Can’t argue with that then.

1 Like
local words = {"If I could see you, I would give you a great big hug!";
    "You are a great person";
    "You are amazing";
    "I know you can do anythig";
    "You are super smart";
    "Tell me more"
}

script.Parent.Activated:Connect(function()
    print({words [math.random(#words)]})
    script.Parent.Text = words[math.random(#words)]
end)

When you’re printing, you have to put the provided items in “()”

Plus, the second error was that you tried to put a table as the text.