Deleting tiles after generation

  1. What do you want to achieve? Keep it simple and clear!
    So I saw Brackeys 's Creating your first game series and really like it. I thought wow thats cool and I never saw something like this on roblox. So lets make this…
  2. What is the issue? Include screenshots / videos if possible!
    The problem was his game was based on levels and it would be very hard to make all the levels and players would get bored easily.
    So what I thought… i thought to make a map generation system.

I followed this video. Which is in Unity cuz I couldn’t really found something I wanted in Roblox. I am a little bit familier with C#.

So now the main problem is:


The speed of ball is slow to show the generation automatic.

I can’t figure out a way to delete tiles in lua. In the video the person is using something called LIST which is in my knowledge a data structure(I am just a kid please correct me if I am wrong) not available in lua…

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have tried using arrays but didn’t went far with it.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

The script:

--Made by Beastcraft_Gaming--
--6/11/20--

--Variables

--Services
local Rs = game:GetService("ReplicatedStorage");
local Ws = game:GetService("Workspace");

--instances
local player = Ws:WaitForChild("player");
local Tiles = Rs:WaitForChild("Tiles"):GetChildren();
local TilesFolder = Instance.new("Folder", Ws); TilesFolder.Name = "TilesFolder"

--Values
local zSpawn : number = 0;
local TileLength = -100;
local numberOfTiles = 1;

--functions

local function SpawnTile(tileIndex : number)
	local tile = Tiles[tileIndex]:Clone();
	
	tile.Parent = TilesFolder;
	
	tile:SetPrimaryPartCFrame(CFrame.new( Vector3.new(0,-10,0 + zSpawn)) * CFrame.Angles(0,math.rad(90),0));
	zSpawn += TileLength;
	print(zSpawn);
end



local function Main()
	
	for i = 1, numberOfTiles, 1 do
		if i == 1 then
			SpawnTile(1);
		else
			local RandNum = math.random(1,#Tiles);
			SpawnTile(RandNum);
		end
	end
	
end

local function Update()
	
	if player.position.z < zSpawn - (numberOfTiles*TileLength)then
		print("Yes");
		local RandNum = math.random(1,#Tiles);
		SpawnTile(RandNum);
		
	end
	
end

--Main
local thread = coroutine.wrap(function()
	while true do
		Update();
		wait(0.1);
	end
end)
thread();

Main();



Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

So Basically are you trying to do is when the ball touches the tile , it dissapears? If then you can use a touched event and when the Ball touches the tile destroy the tile or slowly change its transparency to 0 ( to make it look cool) and destroy it or if you want it dissapear after sometime it is spawned you can create a new tile as an instance and do debris:AddItem(tile , time) here time is basically for how long the tile should remain for.

1 Like

Is there any way to change the time according to the speed of ball so I don’t have to change the time everytime I change the speed

the list thing is very similar to the tables in roblox u can use tht

Well you can use some math for that like debris:AddItem(tile , speedofball/2) or something Its upto you how you want it

When you’re updating the level generation, you’re checking to see if any tiles are close enough to the player that they should be generated. You need to also check if any of the generated tiles have gone far enough away that they should be unloaded.

You SpawnTile function puts tiles inside the TilesFolder, so you can check each individual tile that has already been generated and see if it’s far enough away that it should be unloaded. If that’s the case, you can just call :Destroy() on the tile.

1 Like

I am not on my PC rn I will try all your solutions once I am on and Thanks to everyone for replieing.

1 Like