function Round()
plates = {}
for i = 1, 64 do
table.insert(plates, i, tostring(i))
end
while wait(SpeedLevel / 250) do
local PlateFall = coroutine.wrap(function(part, warningtime)
if part.BrickColor == BrickColor.new(255, 0, 0) then
return
end
part.BrickColor = BrickColor.new(255, 0, 0)
Sounds.Beep:Clone().Parent = part
part.Beep.Playing = true
part.Beep.Looped = true
print("AhhhrreeeEEEEEEE")
wait(warningtime)
part.Beep:Destroy()
part.Anchored = false
end)
local choice = math.random(plates[1], #plates)
PlateFall((game.Workspace.DefaultBoard:FindFirstChild(tostring(choice))), 0.3)
table.remove(plates, choice)
wait()
end
end
Iām trying to make falling plates. Iāve tried some things, but my script is STILL trying to call for destroyed table values. Might have rewrite this again.
I believe the issue is that āchoiceā is a string, and for table.remove to work correctly it needs a numbered key. Perhaps if you call tonumber on it, it would work?
example:
table.remove(plates,tonumber(choice))
Really unsure if I even read your code correctly. Although I would still give this a shot.
Doesnāt work. I tried something else too, butā¦ this is hard to explain and my code is trash, so I might as well give you more of the script. Itās pretty much gibberish, so ask if you need to know something specific.
CollectionSerice = game:GetService("CollectionService")
RemoteEvent = game.ReplicatedStorage.RemoteEvent
Lighting = game.Lighting
ScreenGui = Lighting.ScreenGui
TextButton = ScreenGui.TextButton
Sounds = game.Lighting.Sounds
plates = {}
SpeedLevel = 99
for i = 1, 64 do
table.insert(plates, i, tostring(i))
end
...cut a part out
function Regenerate()
for i, v in pairs(game.Workspace.ProtectionBoard:GetChildren()) do
v.CanCollide = true
v.Transparency = 0.8
end
for i, v in pairs(game.Workspace.DefaultBoard:GetChildren()) do
v:Destroy()
end
wait(1)
for i, v in pairs(game.Workspace.ProtectionBoard:GetChildren()) do
v.CanCollide = false
v.Transparency = 1
end
game.Lighting.DefaultBoard:Clone().Parent = game.Workspace
for i, v in pairs(game.Workspace.DefaultBoard:GetChildren()) do
local question = 0
question = math.random(1, #plates)
v.Name = plates[question]
table.remove(plates, question)
end
end
function Round()
plates = {}
for i = 1, 64 do
table.insert(plates, i, tostring(i))
end
while wait(SpeedLevel / 250) do
local PlateFall = coroutine.wrap(function(part, warningtime)
if part.BrickColor == BrickColor.new(255, 0, 0) then
return
end
part.BrickColor = BrickColor.new(255, 0, 0)
Sounds.Beep:Clone().Parent = part
part.Beep.Playing = true
part.Beep.Looped = true
print("AhhhrreeeEEEEEEE")
wait(warningtime)
part.Beep:Destroy()
part.Anchored = false
end)
local choice = math.random(plates[1], #plates)
PlateFall((game.Workspace.DefaultBoard:FindFirstChild(tostring(choice))), 0.3)
for i, v in pairs(plates) do
if v == choice then
table.remove(i)
end
end
wait()
end
end
This is actually stumping me a bit. I mean, not sure if this would change anything but for your āchoiceā declaration I think itād be better if you wrote it like this:
local choice = math.random(1,#plates)
I actually question how that works, because the values of your table are strings from what Iāve seen? Maybe it converts it to numbers automaticallyā¦I have no idea.
I do also question why you run the same loop twice? (When you add the plates to the table.)
These were the only things that jumped out at me, can look at it again if this isnāt helpful whatsoever.
At a glance, it looks like your loop keeps running even after youāve emptied the plates table (removed all the values). At that point, I would expect you to āget bad argument #2 to randomā errors. And like C_Sharper noted, the first argument to math.random cannot be plates[1], that basically guarantees an empty interval, since plates[1] will often evaluate to a number larger than #plates. It has to be math.random(1,#plates) and you have to stop the loop when #plates is 0.