Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What's with this error, "invalid argument #1 to 'pairs' (table expected, got string)"?

I understand there's something wrong with the defined variables. How do I go about making a table where the values are directories to parts?

local changeFrequency = game.Workspace.colorChangingBricks.changeFrequency.Value

local floorTiles = {script.Parent.danceFloorTile1,
	script.Parent.danceFloorTile2,
	script.Parent.danceFloorTile3,
	script.Parent.danceFloorTile4,
	script.Parent.danceFloorTile5,
	script.Parent.danceFloorTile6,
	script.Parent.danceFloorTile7,
	script.Parent.danceFloorTile8,
	script.Parent.danceFloorTile9,
	script.Parent.danceFloorTile10,
	script.Parent.danceFloorTile11,
	script.Parent.danceFloorTile12,
	script.Parent.danceFloorTile13,
	script.Parent.danceFloorTile14,
	script.Parent.danceFloorTile15,
	script.Parent.danceFloorTile16,
	script.Parent.danceFloorTile18}

local colors = {BrickColor.new("Bright red").Color,
	BrickColor.new("Bright yellow").Color,
	BrickColor.new("Dark orange").Color,
	BrickColor.new("Bright orange").Color,
	BrickColor.new("Medium red").Color,
	BrickColor.new("Neon orange").Color,
	BrickColor.new("Daisy orange").Color}

local tweenService = game:GetService("TweenService")

local floorTiles = ("Neon")

function ColorChange(colorToChangeTo)
	local tweenInformation = TweenInfo.new(1)
	local ColorProperty = {}

	ColorProperty.Color = colorToChangeTo

	for i,v in pairs(floorTiles) do
		local tween =

			tweenService:Create(v, tweenInformation, ColorProperty)
	end

	tween:Play()

	wait(changeFrequency)

end

while true do
	for i, v in ipairs(colors) do
		ColorChange(v)
	end
end 

2 answers

You made two variables, both called floorTiles. One is a string and the other is a table, so the script used the string.

You need to use :GetChildren() or :GetDescendants() then it can go through all the objects inside your table. You cant loop through name/string "floorTiles"

This discussion is preserved as it was. New answers, comments, and votes are closed.