Can't Assign Random String to Text String

My code:

local time = 1
local topicsranom = { "tsrar Nine","TWO" }

while wait(time) do
	topicsranom = topicsranom[math.random(1,#topicsranom)]
	
	game.Lighting.TimeOfDay = 3
	wait(time)
	game.Lighting.TimeOfDay = 14
	local cln = game.Lighting.Newspaper:Clone()
	cln.Parent = workspace
	
	cln.SurfaceGui.Attention.Text = topicsranom -- error
end

It supposed to do random text on the block but it will display error

 Unable to assign property Text. string expected, got nil 
2 Likes

On the first loop, you’re redefining the table to a value.

local time = 1
local topicsranom = { "tsrar Nine","TWO" }

while wait(time) do
	local selected = topicsranom[math.random(1,#topicsranom)]
	-- change the variable to something else

	game.Lighting.TimeOfDay = 3
	wait(time)
	game.Lighting.TimeOfDay = 14
	local cln = game.Lighting.Newspaper:Clone()
	cln.Parent = workspace
	
	cln.SurfaceGui.Attention.Text = selected
end
1 Like

Oh it works I thought it was something simple that was the error, thank you for helping me

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