I'm making a randomly generated Area by going through each location, and then recalculating chance. I'm using game:GetService("RunService").Heartbeat:wait() to slow down the script so it doesn't do it all at once and lag the server.
local player = game.Players.LocalPlayer
local rebirths = player.leaderstats.Rebirths.Value
local button = script.Parent
local Prefabs = game.ReplicatedStorage.Prefabs
local cubes = 90
local width = 100
local length = 50
local height = 6
local X = 0
local Y = 0
local Z = 0
local rows = 1
local w = 0
local l = 0
local h = 0
local chance = 0
math.randomseed(tick())
function DrawBlock(block, xp, yp, zp, location, num)
if num == "" then
local newBlock = Prefabs[block]:Clone()
newBlock.Parent = location
newBlock.Size = Vector3.new(3,3,3)
newBlock.CFrame = CFrame.new(xp,yp,zp)
else
local newBlock = Prefabs[block]:Clone()
newBlock.Parent = location
newBlock.CFrame = CFrame.new(xp,yp,zp)
newBlock.Size = Vector3.new(3,3,3)
end
end
button.MouseButton1Click:connect(function()
if player.TeamColor == BrickColor.new("Really blue") then
local X = 148.95
local Y = -102
local Z = 615.84
while h ~= height do
chance = math.random(100)/100
if l == length then
w = 0
l = 0
Z = 615.84
X = 148.95
Y = Y-3
h = h+1
elseif w == width then
w = 0
Z = Z-3
X = 148.95
l = l+1
elseif chance<1 and chance>.85 then
DrawBlock("Iron",X,Y,Z,workspace.ReallyBlueBase,"")
w = w+1
X = X-3
elseif chance<.84 and chance>.74 then
DrawBlock("Coal",X,Y,Z,workspace.ReallyBlueBase,"")
w = w+1
X = X-3
else
DrawBlock("Stone",X,Y,Z,workspace.ReallyBlueBase,"")
w = w+1
X = X-3
end
game:GetService("RunService").Heartbeat:wait()
end
end
end)
Thanks in advance!

1 comment
Try putting wait(timehere) in the script above and tell me what you get. Do it at the main parts of where it sends and changes these colors.