I am trying to make a randomizer that draws a number and then a button that removes a value in an array.
This is the code that is triggered by pressing the brick that picks a random number from the table.
values = {"2", "7", "0", "5", "3", "X", "X", "X"} function draw() script.Parent.Value.Value = values[math.random(#values)] script.Parent.Chip.SurfaceGui.TextLabel.Text = script.Parent.Value.Value end script.Parent.Button.ClickDetector.MouseClick:Connect(draw)
And this is the other code that is supposed to remove the specific value. It is fired by a different brick.
function show2() table.remove(values, 1) game.Workspace.Digits.Two.Transparency=0.8 wait(0.05) game.Workspace.Digits.Two.Transparency=0.6 wait(0.05) game.Workspace.Digits.Two.Transparency=0.4 wait(0.05) game.Workspace.Digits.Two.Transparency=0.2 wait(0.05) game.Workspace.Digits.Two.Transparency=0 wait(0.05) end script.Parent.firstnumber.ClickDetector.MouseClick:Connect(show2)
The 2 will be removed and 7 will take its place. But I have another block of code that is supposed to remove 7 when I press another button.
Is this possible to do?
You can use this function to remove a value from a table:
function removeVal(tablee, value) -- second array is the value you want to find in the table (can be a string, object, number, etc) for i, v in pairs(tablee) do if v == value then print("removing " .. tostring(value)) table.remove(tablee, i) -- 'i' is the position of the found variable in the table end end end --Example: local Values = {"2", 7", "0", "5", "3", "X", "X", "X"} removeVal(Values, "2")