Corruption Like Effect, tiles

I am trying to make a sort of “corruption” with the tiles (it slowly takes more and more tiles and expands). I tried making it so that after a certain amount of times it corrupts more & more tiles, something similar to how I have tried to show in this image.

The only problem is that instead it takes like chunks instead of following a square pattern & I wanted to know what was my problem here’s the code.

local TilesBanned = {"TallTile","TallERTile"}

	local function tileChoose()

		local tilesF = workspace.Tiles:GetChildren()
		local rndTile = tilesF[math.random(1,#tilesF)]
		local tile = rndTile

		if table.find(TilesBanned,tile.TileName.Value) then
			return tileChoose()
		else
			return tile
		end

	end

	local chosenTile = tileChoose()
	
	chosenTile.PrimaryPart.Material = Enum.Material.Plastic
	chosenTile.PrimaryPart.MaterialVariant = "Fleshling2"
	chosenTile.PrimaryPart.Color = Color3.fromRGB(255,255,255)
	
	local bool = Instance.new("BoolValue")
	bool.Parent = chosenTile
	bool.Name = "Slower"
	
	local FarEnd = Instance.new("ObjectValue")
	FarEnd.Name = "FarEnd"
	FarEnd.Parent = chosenTile
	FarEnd.Value = Screeching

	local Timer = 4
	local Range = 0 -- change goes up when more tiles corrupt
	
	local BannedTilesToNotCorrupt = {}
	
	table.insert(BannedTilesToNotCorrupt,chosenTile)
	local SizeCorruption = 0
	local Corruption = 0
	
	while task.wait(Timer) do
		
		Corruption += 9
		
		for i, y in pairs(workspace.Tiles:GetChildren()) do
			if y:FindFirstChild("FarEnd") and y:IsA("Model") then
				if y:FindFirstChild("FarEnd").Value == Screeching then
					
					if SizeCorruption <= Corruption then
						
						SizeCorruption += .5

						
						table.insert(BannedTilesToNotCorrupt,y)
						y:FindFirstChild("FarEnd"):Destroy()
						
						
						local function getAllAroundParts(part)

							local function FindTile(bool,tileIs)

								if workspace.Tiles:GetChildren() == nil then
									return
								end

								local Row = tileIs.Row
								local Collum = tileIs.Collum

								if bool == "+" then

									for i, v in pairs(workspace.Tiles:GetChildren()) do

										if v:IsA("Model") then
											if v.Row.Value == Row.Value + 1 and v.Collum.Value == Collum.Value then
												return v
											end
										end

									end

								else

									for i, v in pairs(workspace.Tiles:GetChildren()) do

										if v:IsA("Model") then
											if v.Row.Value == Row.Value - 1 and v.Collum.Value == Collum.Value then
												return v
											end
										end

									end

								end

							end

							local TableOfTiles = {}

							local getTile1 = workspace.Tiles:FindFirstChild(tostring(tonumber(part.Name)+1))
							local getTile2 = workspace.Tiles:FindFirstChild(tostring(tonumber(part.Name)-1))

							local rowL1 = FindTile("+",part)
							local rowR1 = FindTile("-",part)

							if getTile1 then
								local rowL2 = FindTile("+",getTile1)
								local rowR2 = FindTile("-",getTile1)

								if rowL2 ~= nil then
									table.insert(TableOfTiles,rowL2)
								end

								if rowR2 ~= nil then
									table.insert(TableOfTiles,rowR2)
								end

								table.insert(TableOfTiles,getTile1)


							end

							if getTile2 then
								local rowL3 = FindTile("+",getTile2)
								local rowR3 = FindTile("-",getTile2)


								if rowL3 ~= nil then
									table.insert(TableOfTiles,rowL3)
								end

								if rowR3 ~= nil then
									table.insert(TableOfTiles,rowR3)
								end

								table.insert(TableOfTiles,getTile2)

							end

							table.insert(TableOfTiles,part)

							if rowL1 ~= nil then
								table.insert(TableOfTiles,rowL1)
							end

							if rowR1 ~= nil then
								table.insert(TableOfTiles,rowR1)
							end			

							return TableOfTiles

						end

						local getparts = getAllAroundParts(y)

						print(getparts)

						for i, v in pairs(getparts) do
							if v:IsA("Model") then

								if not table.find(BannedTilesToNotCorrupt,v) then


									v.PrimaryPart.Material = Enum.Material.Plastic
									v.PrimaryPart.MaterialVariant = "Fleshling2"
									v.PrimaryPart.Color = Color3.fromRGB(255,255,255)

									local bool = Instance.new("BoolValue")
									bool.Parent = v
									bool.Name = "Slower"
								
								
									local FarEnd = Instance.new("ObjectValue")
									FarEnd.Name = "FarEnd"
									FarEnd.Parent = v
									FarEnd.Value = Screeching

								end

							end


						end

					
					end
					
				end
			end
		end
		
		
	end

i’m still unsure what your goal is but is this what you’re aiming for??

Yes looking for something like this, the issue is when I do it it goes up a lot & takes the whole map in various pattern instead of going 1 tile at the time

i’m still unsure of the issue but here’s my code that i have shown in the video, apologies in advance because i cannot explain how it works as i’m tired

local Tiles = setmetatable({}, {__index = table}) :: {[Part] : Vector2}

local TilesX = 9
local TilesY = 9

local SpacingX = 1
local SpacingY = 1

local TileWidth = 4
local TileHeight = 4

local CircularCorruption = true

for Y = 1, TilesY do
	for X = 1, TilesX do
		local Tile = Instance.new('Part')
		Tile.Size = Vector3.new(TileWidth, 0.1, TileHeight)
		Tile.Position = Vector3.new((X - 1) * (TileWidth + SpacingX), 0, (Y - 1) * (TileHeight + SpacingY))
		Tile.Anchored = true
		Tile.Color = Color3.fromRGB(255, 255, 255)
		Tile.Parent = script.Parent
		Tiles[Tile] = Vector2.new(X, Y)
	end
end

local SafeTiles = Tiles:clone() :: typeof(Tiles)

local CorruptionLevel = 0
local CorruptionStartX = math.ceil(TilesX / 2)
local CorruptionStartY = 0

local VC = Vector2.new(CorruptionStartX, CorruptionStartY)

local function Circular(Position, Corruption)
	return (Position - VC).Magnitude <= (Corruption).Magnitude
end
local function Square(Position, Corruption)
	return (Position.X <= CorruptionStartX + Corruption.X and Position.X >= CorruptionStartX - Corruption.X) 
			and (Position.Y <= CorruptionStartY + Corruption.Y and Position.Y >= CorruptionStartY - Corruption.Y)
end

while task.wait(1) do -- change duration to your liking
	CorruptionLevel += 1

	local CorruptionPosition = CorruptionLevel * Vector2.new(1, 1)
	for Tile, Position in SafeTiles do
		if (CircularCorruption and Circular(Position, CorruptionPosition)) or (not CircularCorruption and Square(Position, CorruptionPosition)) then
			SafeTiles[Tile] = nil
			
			-- do whatever you want with the color of the tiles here
			local tw = game.TweenService:Create(Tile, TweenInfo.new(0.15), {Color = Color3.fromRGB(0, 0, 0)})
			tw.Completed:Connect(function()
				game.TweenService:Create(Tile, TweenInfo.new(0.5), {Color = Color3.fromRGB(255, 0, 0)}):Play()
			end)
			tw:Play()
		end
	end
end
1 Like

Do not worry Ill understand it when ill be back home, ty for helping me!

1 Like

Alright when I was about to write how I can fix a certain issue I had I just managed to fix it like right now :sob: Idk How I managed to fix It but I tried remaking a system with more functions. Here is my updated code

local FarEnd = Instance.new("ObjectValue")
	FarEnd.Name = "FarEnd"
	FarEnd.Parent = chosenTile
	FarEnd.Value = Screeching

	local Timer = 4
	local Range = 0 -- change goes up when more tiles corrupt
	
	game.Debris:AddItem(FarEnd,Timer*1.2)

	
	local BannedTilesToNotCorrupt = {}
	
	local SizeCorruption = 0
	local Corruption = 0
	
	local function getAllAroundParts(part)

		local function FindTile(bool,tileIs)

			if workspace.Tiles:GetChildren() == nil then
				return
			end

			local Row = tileIs.Row
			local Collum = tileIs.Collum

			if bool == "+" then

				for i, v in pairs(workspace.Tiles:GetChildren()) do

					if v:IsA("Model") then
						if v.Row.Value == Row.Value + 1 and v.Collum.Value == Collum.Value then
							return v
						end
					end

				end

			else

				for i, v in pairs(workspace.Tiles:GetChildren()) do

					if v:IsA("Model") then
						if v.Row.Value == Row.Value - 1 and v.Collum.Value == Collum.Value then
							return v
						end
					end

				end

			end

		end

		local TableOfTiles = {}

		local getTile1 = workspace.Tiles:FindFirstChild(tostring(tonumber(part.Name)+1))
		local getTile2 = workspace.Tiles:FindFirstChild(tostring(tonumber(part.Name)-1))

		local rowL1 = FindTile("+",part)
		local rowR1 = FindTile("-",part)

		if getTile1 then
			local rowL2 = FindTile("+",getTile1)
			local rowR2 = FindTile("-",getTile1)

			if rowL2 ~= nil then
				table.insert(TableOfTiles,rowL2)
			end

			if rowR2 ~= nil then
				table.insert(TableOfTiles,rowR2)
			end

			table.insert(TableOfTiles,getTile1)


		end

		table.insert(TableOfTiles,part)

		if getTile2 then
			local rowL3 = FindTile("+",getTile2)
			local rowR3 = FindTile("-",getTile2)


			if rowL3 ~= nil then
				table.insert(TableOfTiles,rowL3)
			end

			if rowR3 ~= nil then
				table.insert(TableOfTiles,rowR3)
			end

			table.insert(TableOfTiles,getTile2)

		end

		if rowL1 ~= nil then
			table.insert(TableOfTiles,rowL1)
		end

		if rowR1 ~= nil then
			table.insert(TableOfTiles,rowR1)
		end			

		return TableOfTiles

	end
	
	while task.wait(Timer) do
		
		Corruption += 1
		
		--[[for i, y in pairs(workspace.Tiles:GetChildren()) do
			if y:FindFirstChild("FarEnd") and y:IsA("Model") then
				if y:FindFirstChild("FarEnd").Value == Screeching then
					
					if SizeCorruption <= Corruption then
						
						SizeCorruption += .5
						
						
						table.insert(BannedTilesToNotCorrupt,y)
						y:FindFirstChild("FarEnd"):Destroy()
						
						
						local function getAllAroundParts(part)

							local function FindTile(bool,tileIs)

								if workspace.Tiles:GetChildren() == nil then
									return
								end

								local Row = tileIs.Row
								local Collum = tileIs.Collum

								if bool == "+" then

									for i, v in pairs(workspace.Tiles:GetChildren()) do

										if v:IsA("Model") then
											if v.Row.Value == Row.Value + 1 and v.Collum.Value == Collum.Value then
												return v
											end
										end

									end

								else

									for i, v in pairs(workspace.Tiles:GetChildren()) do

										if v:IsA("Model") then
											if v.Row.Value == Row.Value - 1 and v.Collum.Value == Collum.Value then
												return v
											end
										end

									end

								end

							end

							local TableOfTiles = {}

							local getTile1 = workspace.Tiles:FindFirstChild(tostring(tonumber(part.Name)+1))
							local getTile2 = workspace.Tiles:FindFirstChild(tostring(tonumber(part.Name)-1))

							local rowL1 = FindTile("+",part)
							local rowR1 = FindTile("-",part)

							if getTile1 then
								local rowL2 = FindTile("+",getTile1)
								local rowR2 = FindTile("-",getTile1)

								if rowL2 ~= nil then
									table.insert(TableOfTiles,rowL2)
								end

								if rowR2 ~= nil then
									table.insert(TableOfTiles,rowR2)
								end

								table.insert(TableOfTiles,getTile1)


							end

							if getTile2 then
								local rowL3 = FindTile("+",getTile2)
								local rowR3 = FindTile("-",getTile2)


								if rowL3 ~= nil then
									table.insert(TableOfTiles,rowL3)
								end

								if rowR3 ~= nil then
									table.insert(TableOfTiles,rowR3)
								end

								table.insert(TableOfTiles,getTile2)

							end

							table.insert(TableOfTiles,part)

							if rowL1 ~= nil then
								table.insert(TableOfTiles,rowL1)
							end

							if rowR1 ~= nil then
								table.insert(TableOfTiles,rowR1)
							end			

							return TableOfTiles

						end

						local getparts = getAllAroundParts(y)

						print(getparts)

						for i, v in pairs(getparts) do
							if v:IsA("Model") then

								if not table.find(BannedTilesToNotCorrupt,v) then

									local sound = Screeching.HumanoidRootPart:FindFirstChild("Corruption" .. tostring(math.random(1,2))):Clone()
									sound.Parent = v.PrimaryPart
									sound:Play()
									game.Debris:AddItem(sound,sound.TimeLength)

									v.PrimaryPart.Material = Enum.Material.Plastic
									v.PrimaryPart.MaterialVariant = "Fleshling2"
									v.PrimaryPart.Color = Color3.fromRGB(255,255,255)

									local bool = Instance.new("BoolValue")
									bool.Parent = v
									bool.Name = "Slower"
								
								
									local FarEnd = Instance.new("ObjectValue")
									FarEnd.Name = "FarEnd"
									FarEnd.Parent = v
									FarEnd.Value = Screeching

								end

							end


						end

					
					end
					
				end
			end
		end]]
		
		local function GetCorruptionParts()
			
			local TablesForCorrupt = {}
			
			for i, tiles in pairs(workspace.Tiles:GetChildren()) do
				if tiles:IsA("Model") then
					if tiles:FindFirstChild("FarEnd") then
						if tiles:FindFirstChild("FarEnd").Value == Screeching then
						
							table.insert(TablesForCorrupt,tiles)
						
						end
					end
					
				end
			end
			
			return TablesForCorrupt
			
		end
		
		local GetParts = GetCorruptionParts()
		
		
		for i, tile in pairs(GetParts) do
			
			local AroundTile = getAllAroundParts(tile)
			print(AroundTile)
			
			for i, around in pairs(AroundTile) do
				
				if not table.find(BannedTilesToNotCorrupt,around) then
				
					local FarEnd2 = Instance.new("ObjectValue")
					FarEnd2.Name = "FarEnd"
					FarEnd2.Parent = around
					FarEnd2.Value = Screeching
				
					task.wait(.25)
				
					local sound = Screeching.HumanoidRootPart:FindFirstChild("Corruption" .. tostring(math.random(1,2))):Clone()
					sound.Parent = chosenTile.PrimaryPart
					sound:Play()
					game.Debris:AddItem(sound,sound.TimeLength)
				
					around.PrimaryPart.Color = Color3.fromRGB(255,0,0)
					table.insert(BannedTilesToNotCorrupt,around)
					
					game.Debris:AddItem(FarEnd2,Timer*1.2)

				
				end
				
			end
			
		end
		
		--	table.insert(BannedTilesToNotCorrupt,chosenTile)
		
	end
	

To be honest idk how I fixed it but its fixed! Thanks for helping me!

1 Like