Attempt to index number with Color

Greetings, I am trying to script a dancefloor. I created some parts and modeled them. I tried using a for v, _ in pairs loop and GetChildren to get every single part in the dancefloor. But I am getting the error “Attempt to index number with Color”.

Here is the script:

for v, _ in pairs(game.Workspace.DanceFloor:GetChildren()) do
	while true do
		for i=0,1,0.01 do
			v.Color = Color3.fromHSV(i,1,1)
			wait(1)
		end
	end
end
1 Like

You are assigning v as a number instead of the variable.
Replace it with

for _,v in ipairs(workspace.DanceFloor:GetChildren()) do

Also use ipairs for :GetChildren(), it performs faster and instead of game.Workspace do workspace.

1 Like

Okay so now it works, but only for one pad and not all as it should do.

This is because the for loop is yielding so it will wait for the current pad to finish and then move onto the next pad.

Use this instead

local DanceFloorPads = workspace.DanceFloor:GetChildren()

while true do
	for i = 0,1,0.01 do
		for _,Pad in ipairs(DanceFloorPads) do
			v.Color = Color3.fromHSV(i,1,1)
		end
		wait(1)
	end
end