Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The randomized data in a table did not got deleted?

Asked by 4 years ago
Edited 4 years ago

Hello guys! Im trying to make a new code, in workspace I have 4 block from Part1 to Part4. The four blocks are added to the table. The table gets a randomized number from itself, and sets the block at workspace to transparent. My problem is that it is not deleting the data, because im trying to do that if it got the data and set the block to transparent, it needs to delete that data from the table, but it did not did it. Can someone help? Sorry for the bad english, my mother language is not english.

`

local ttable = {"Part1","Part2","Part3","Part4"}

local value = math.random(1,#ttable)
local pickedvalue = ttable[value]
workspace["Part"..value].Transparency = 1
table.remove(ttable, value)

print(tostring(value))

for index = 1, #ttable do
    print(index, ttable[index])
end

`

Thank you!

1 answer

Log in to vote
0
Answered by 4 years ago

The code is fine, the problem is that each time you click, you create a new local table containing 4 items. You are not persisting this table in between clicks.

Pull the table outside of the MouseClick event and add an if statement at the beginning of the click listener to check if there's at least 1 item in the table (otherwise math.random will throw an error)

0
Thank you! BlackFateX 19 — 4y
Ad

Answer this question