I am currently working on a mining game, and when the mine is being created it clones a block and positions it depending on the variables in the code. Everything runs perfectly fine, and I have a Stepped:wait() for every layer that is made. Even though it has this yeild, it still manages to timeout breaking the whole game.
Is there any way I can prevent this? I know other mining games dont have this issue so I know this is possible somehow.
My Script:
--Set Y
for y = 1,HeightSize do
--Set Z
for z = 1,RowSize*2 do
--Set X
for x = 1,RowSize*2 do
local Block = Blocks.Dirt
--Block Type
if Ypos == YConstraint then
Block = Blocks.Dirt
else --Underground
local PossibleBlocks = {}
for _,BlockValue in ipairs(BlockChances) do
if Ypos <= YConstraint*BlockValue.Depth then
for count = 1,BlockValue.Chance do
table.insert(PossibleBlocks,BlockValue)
end
end
end
Block = PossibleBlocks[math.random(1,#PossibleBlocks)].BlockType
end
--Place Block
local NewBlock = Block:Clone()
NewBlock.Position = Vector3.new(Xpos,Ypos,Zpos)
NewBlock.Parent = Mine
Xpos += BlockSize
end
Xpos = -XConstraint
Zpos += BlockSize
end
Zpos = -XConstraint
Ypos -= BlockSize
RunService.Stepped:wait()
end