"attempt to concatenate string with table" error

I’m trying to make a tip randomizer for my game but it keeps returning this error: “attempt to concatenate string with table”

Here’s my script:

local tip = script.Parent
local random1 = math.random(1,6)
local random2 = math.random(1,6)
local random3 = math.random(1,6)

local TipsRandomizer = {
	[1] = {"Scraps can be used to upgrade tools and minecarts."},
	[2] = {"Like for more updates!"},
	[3] = {"Seasons last for 30 days."},
	[4] = {"Don't forget to buy power ups before you ride!"},
	[5] = {"Gems are rare to find on a ride."},
	[6] = {"Certain materials are more durable than others."},
}

while task.wait(2) do
	script.Parent.Text = "Tip:"..TipsRandomizer[math.random(1, #TipsRandomizer)]
end

Any help is appreciated!

This will return a table since the TipsRandomizer table is set up like that:

You’d want to make this line look like this:

script.Parent.Text = "Tip:"..TipsRandomizer[math.random(1, #TipsRandomizer)][1] -- [1] tells Luau to get the first item in the returned table (the string)

Or change the table to only contain strings:

local tip = script.Parent
local random1 = math.random(1,6)
local random2 = math.random(1,6)
local random3 = math.random(1,6)

local TipsRandomizer = {
	[1] = "Scraps can be used to upgrade tools and minecarts.",
	[2] = "Like for more updates!",
	[3] = "Seasons last for 30 days.",
	[4] = "Don't forget to buy power ups before you ride!",
	[5] = "Gems are rare to find on a ride.",
	[6] = "Certain materials are more durable than others.",
}

while task.wait(2) do
	script.Parent.Text = "Tip:"..TipsRandomizer[math.random(1, #TipsRandomizer)]
end
2 Likes

Thank you for the solution. I’ve been trying to find it for hours :smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.