My script is talking to the dead (values)

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.

1 Like

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.

1 Like

Iā€™ll add what you told me to write, and fix the second question.

My coding is messyyyyyyyyyyyyyy

2 Likes

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.

2 Likes