Tiles = Instance.new("Model")
Tiles.Parent = game.Workspace
Tiles.Name = "Tiles"
local red = 0
for i=1,30, 1 do
Brick = Instance.new("Part")
Brick.Name = i
brickArray = {}
table.insert(brickArray, i)
Brick.Parent = game.workspace.Tiles
Brick.Anchored = true
Brick.Size = Brick.Size + Vector3.new(20,0,22)
Brick.Color = Color3.fromRGB(0,0,0)
Brick.Locked = false
if i < 6 then
Brick.CFrame = CFrame.new(24*i,0,0)
elseif i < 12 then
Brick.CFrame = CFrame.new(24*(i-6),0,24)
elseif i < 18 then
Brick.CFrame = CFrame.new(24*(i-12),0,48)
elseif i < 24 then
Brick.CFrame = CFrame.new(24*(i-18),0,72)
elseif i < 30 then
Brick.CFrame = CFrame.new(24*(i-24),0,96)
end
print(brickArray[1])
end
local blocks = 30
local Parent = game.Workspace.Tiles --- Here you write where all the tiles are
local children = Parent:GetChildren()
for i = 0,30 do
for i,v in pairs(children) do --- A script that goes through all the children of your parent
v.Touched:connect(function()
red = v.Color.r * 255
v.Color = Color3.fromRGB(red + 2, 0)
if red >= 220 then
v.Anchored = false
blocks = blocks - 1
end
end)
wait(0.4)
end
end
I'm trying to make a game where the tiles start off black, and as they are stepped on become more red. So far it works, but I have a couple issues I can't seem to fix. First, the 30th tile seems to not activate at the same time as the others. It takes a few seconds before it registers touched events unlike the other tiles.
And second, and I can't figure out a way to randomly select a block out of the 30 to add extra red to. What I want is for some blocks to randomly get a bit more red around the map, but I can't figure out a way to do this without interrupting the rest of the script. Using a for or while loop takes over the rest of the script, so I can't figure out how to properly implement my idea.

2 comments
The problem I found was that the wait(0.4) is affecting when each part is allowed to be touched on.
Not a full answer but for the for loop or a while loop you can use spawn(). spawn() would run the function passed separately from the script.