I have tried replacing some of my if statements in my generation code with switch statements which turn turns out actually work in roblox. I keep getting this error I dont know how to replace. (I know the issue but I have no idea how else I can put both of these variables) heres the code:
local progress = false
local function gen()
for x, block in pairs(workspace:WaitForChild("blocks"):GetChildren()) do
if block:IsA("BasePart") then
local ui = game:GetService("ReplicatedStorage"):WaitForChild("UI"):Clone()
ui.Adornee = block
ui.Parent = block
ui:WaitForChild("Text").TextColor3 = block.Color
if block:FindFirstChild("deep") then
else
local deep = Instance.new("NumberValue",block)
deep.Name = "deep"
if block.Position.Y == Vector3.new(0,-5.5,0) then
deep.Value = 1
elseif block.Position.Y == Vector3.new(0,-9.5,0) then
deep.Value = 2
elseif block.Position.Y == Vector3.new(0,-13.5,0) then
deep.Value = 3
elseif block.Position.Y == Vector3.new(0,-17.5,0) then
deep.Value = 4
elseif block.Position.Y == Vector3.new(0,-21.5,0) then
deep.Value = 5
elseif block.Position.Y == Vector3.new(0,-25.5,0) then
deep.Value = 6
elseif block.Position.Y == Vector3.new(0,-29.5,0) then
deep.Value = 7
elseif block.Position.Y == Vector3.new(0,-33.5,0) then
deep.Value = 8
elseif block.Position.Y == Vector3.new(0,-37.5,0) then
deep.Value = 9
elseif block.Position.Y == Vector3.new(0,-41.5,0) then
deep.Value = 10
elseif block.Position.Y == Vector3.new(0,-45.5,0) then
deep.Value = 11
elseif block.Position.Y == Vector3.new(0,-49.5,0) then
deep.Value = 12
elseif block.Position.Y == Vector3.new(0,-53.5,0) then
deep.Value = 13
elseif block.Position.Y == Vector3.new(0,-57.5,0) then
deep.Value = 14
elseif block.Position.Y == Vector3.new(0,-61.5,0) then
deep.Value = 15
elseif block.Position.Y == Vector3.new(0,-65.5,0) then
deep.Value = 16
elseif block.Position.Y == Vector3.new(0,-69.5,0) then
deep.Value = 17
elseif block.Position.Y == Vector3.new(0,-74.5,0) then
deep.Value = 18
elseif block.Position.Y == Vector3.new(0,-78.5,0) then
deep.Value = 19
elseif block.Position.Y == Vector3.new(0,-82.5,0) then
deep.Value = 20
elseif block.Position.Y == Vector3.new(0,-86.5,0) then
deep.Value = 21
elseif block.Position.Y == Vector3.new(0,-90.5,0) then
deep.Value = 22
elseif block.Position.Y == Vector3.new(0,-94.5,0) then
deep.Value = 23
elseif block.Position.Y == Vector3.new(0,-98.5,0) then
deep.Value = 24
elseif block.Position.Y == Vector3.new(0,-102.5,0) then
deep.Value = 25
elseif block.Position.Y == Vector3.new(0,-106.5,0) then
deep.Value = 26
elseif block.Position.Y == Vector3.new(0,-109.5,0) then
deep.Value = 27
elseif block.Position.Y == Vector3.new(0,-114.5,0) then
deep.Value = 28
end
end
if block:FindFirstChild("bedrock") then
block.BrickColor = BrickColor.new("Black metallic")
local click = game:GetService("ReplicatedStorage"):WaitForChild("c2"):Clone()
click.Parent = block
click:WaitForChild("s").Disabled = false
else
local click = game:GetService("ReplicatedStorage"):WaitForChild("c"):Clone()
click.Parent = block
local chance = math.random(0,1421)
local switch = {
[chance < 10 and block:WaitForChild("deep").Value > 3 and block:WaitForChild("deep").Value< 17] = function() -- for case 1
block.BrickColor = BrickColor.new("Persimmon")
block:WaitForChild("strength").Value = 100
end,
[chance < 20 and chance > 10 and block:WaitForChild("deep").Value > 10] = function() -- for case 2
block.BrickColor = BrickColor.new("Pastel green")
block:WaitForChild("strength").Value = 75
end,
[chance < 261 and chance > 20] = function() -- for case 3
block.BrickColor = BrickColor.new("Medium stone grey")
end,
[chance < 420 and chance > 261 and block:WaitForChild("deep").Value > 3] = function()
block.BrickColor = BrickColor.new("Black")
block:WaitForChild("strength").Value = 15
end,
[chance < 620 and chance > 420] = function()
block.BrickColor = BrickColor.new("Black")
block:WaitForChild("strength").Value = 15
end,
[chance < 920 and chance > 620] = function()
block.BrickColor = BrickColor.new("Dark stone grey")
block:WaitForChild("strength").Value = 10
end,
[chance < 920 and chance > 620 and block:WaitForChild("deep").Value > 1] = function()
block.BrickColor = BrickColor.new("Quill grey")
block:WaitForChild("strength").Value = 25
end,
[chance < 1420 and chance > 1320 and block:WaitForChild("deep").Value > 3] = function()
block.BrickColor = BrickColor.new("Gold")
block:WaitForChild("strength").Value = 50
end}
local f = switch[chance, block:WaitForChild("deep").Value] -- this is the line I have an issue with
if(f) then
f()
else
if block:WaitForChild("deep").Value > 15 then
block.BrickColor = BrickColor.new("Bright blue")
block:WaitForChild("strength").Value = 200
else
block.BrickColor = BrickColor.new("Medium stone grey")
end
end
click:WaitForChild("s").Disabled = false
end
end
end
end
gen()
local check = coroutine.wrap(function()
while wait() do
local count = 0
for x = 1, #workspace:WaitForChild("blocks"):GetChildren() do
count = count + 1
end
if count < 2520 / 2.5 and progress == false then
progress = true
game:GetService("ReplicatedStorage"):WaitForChild("time"):FireAllClients()
wait(10)
for x, plr in pairs(game:GetService("Players"):GetChildren()) do
plr.Character:MoveTo(Vector3.new(-4, 6, 4))
end
workspace:WaitForChild("blocks"):Destroy()
local folder = game:GetService("ReplicatedStorage"):WaitForChild("blocks"):Clone()
folder.Parent = workspace
gen()
wait(1)
progress = false
else
wait(1)
end
end
end)
check()
local checky = coroutine.wrap(function()
local count = 0
while wait(1) do
count = count + 1
if count >= 1800 and progress == false then
progress = true
game:GetService("ReplicatedStorage"):WaitForChild("time"):FireAllClients()
wait(10)
for x, plr in pairs(game:GetService("Players"):GetChildren()) do
plr.Character:MoveTo(Vector3.new(-4, 6, 4))
end
workspace:WaitForChild("blocks"):Destroy()
local folder = game:GetService("ReplicatedStorage"):WaitForChild("blocks"):Clone()
folder.Parent = workspace
gen()
wait(1)
progress = false
elseif count >= 1800 and progress == true then
count = 0
end
end
end)
checky()