Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script removing a string in a table. Expects a number??

There's a table with strings in it. For every time the script runs through one string of PurchasedEmotes, it will check if there are any duplicate purchases. The problem lies in Line 12, table.remove(PurchasedEmotes,PurchasedEmotes[i]) where the script says bad argument #2 (number expected, got string) when the whole table is strings only. And I have listed which number of PurchasedEmotes to get rid of, being [i] Can someone help me out?


for i = 1,#PurchasedEmotes do
    print(PurchasedEmotes[i])
    
    if #FindDupesTable == 0 then
        table.insert(FindDupesTable,PurchasedEmotes[i])
        print("first one")
    end
    
    for n = 1,#FindDupesTable do
        if PurchasedEmotes[i] == FindDupesTable[n] then
            table.remove(PurchasedEmotes,PurchasedEmotes[i])--???
            print("found a duplicate.")
            
        else
            table.insert(FindDupesTable,PurchasedEmotes[i])
            print("not a dupe")
        end 
    end
end

1 answer

✓ Accepted answer

The error I found is that you are indexing the table with i, which will return the value at that spot.

To fix this, just simply remove PurchasedEmotes[i] and replace it with i.

Like so...

for i = 1,#PurchasedEmotes do
	print(PurchasedEmotes[i])
	print(i)
	
	if #FindDupesTable == 0 then
		print(i)
		print("First")
		print(PurchasedEmotes[i])
		table.insert(FindDupesTable, PurchasedEmotes[i])
	end

	for n = 1,#FindDupesTable do
		if i == n then
			print("Found Duplicate: "..PurchasedEmotes[i])
			table.remove(PurchasedEmotes, i)
		else
			print("Not a Duplicate")
			table.insert(FindDupesTable, PurchasedEmotes[i]
		end
	end
end

Hope this helped! Feel free to select this as an answer if this worked for you!

2 comments

0

Thanks!

0

Np glad to help!

This discussion is preserved as it was. New answers, comments, and votes are closed.