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

How would I remove an object from a table without setting it to nil?

Asked by
BRAEGON -8
4 years ago

So I am trying to make a card game from Roblox, my main script is set to select all 52 cards of a random deck (there are many different decks with different colors for the cards) and insert all the cards to a table, the game will give each player their amount of cards (in this case 2 for poker) and will never give out the same card twice, there is more to it than this and it has to be table-based. At the end of every round, the script must remove all the cards from the table so that they can be replaced with different cards from a different deck. i tried using a for loop and table. remove but I got an error because it expected an object and not a number. I then tried to use

for i = 1, #cardsInRound do --cards in the round as in the cards loaded from the deck cardsInRound[i] = nil end

this works just fine but the next round I get this error

16:34:50.476 - The Parent property of S8 is locked, current parent: NULL, new parent gameCards

(s8 is a card, the 9 of spades, it works with a number score system)

if it makes a difference this is the code that loads the cards, there are only two themes ATM but I plan on adding many more in the future, this code is really simple but is causing me a lot of problems

function LoadCards()
    if cardTheme == 0 then
        for i = 1, #redCards do
            table.insert(cardsInRound, redCards[i])

        end
    else if cardTheme == 1 then
        for i = 1, #blueCards do
            table.insert(cardsInRound, blueCards[i])

        end
    end

end
end

thanks for any help!

0
Please insert the ENTIRE code that you’ve tried with setting the table value to nil. Something must’ve went wrong, this should never happen. SmartNode 383 — 4y
0
A quick google search reveals that that error supposedly appears when you try to reparent somthing too quickly. @SmartNode is right, can you post the full code? whenallthepigsfly 541 — 4y
0
sure, this is really all the code that has anything to do with the removal though BRAEGON -8 — 4y

1 answer

Log in to vote
0
Answered by
BRAEGON -8
4 years ago

I figured out the problem, I made a mistake in my code where when the card was inserted it wasn't a clone, this caused the problem where once the card was set to nil and the server chose it again on another round it wasn't available

Ad

Answer this question