Getting "attempt to index nil with 'Play'

Having issue with creating color changing floor tiles. The exact error reads: Workspace.colorChangingBricks.DanceFloor.color1tiles.colorChange:43: attempt to index nil with ‘Play’. I’m new to using tween functions.

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")

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 

I think the issue is with these lines, try putting the “tween:Play()” In the for loop.

1 Like

I think its because your tween is inside the loop so tween outside the loop cant be called

2 Likes

@j4ged is correct. You can’t use a local variable outside of its scope.

for i,v in pairs(floorTiles) do
    local tween = tweenService:Create(v, tweenInformation, ColorProperty)
    tween:Play() -- use it here because it's defined here
end

Edit: replied to the wrong person originally

1 Like

Completely missed that, thanks!