Hello! This may sound confusing the way I word this, but here you go.
The issue I am having is to do with “mass pet deletion,” if you get what I mean. You select the option to mass delete pets, click on the ones you want to delete, and confirm. I got that down. I scripted it, however I’m having this issue that I haven’t been able to figure out for hours.
On the client, I have a table of unique pet ids that gets added on to with my UpdatePets() function. This function makes the pet buttons, etc. Once the player clicks on the Mass Delete Pets button, I add every pet id to the table they selected. That works fine.
Adding to the table looks like this:
if petids[petID] then -- checks if the pet id is already in the table and removes it
petids[petID] = nil
else
petids[petID] = true
end
You shouldn’t need the rest of the updatepets function code, since that is irrelevant. Now for real main case, I believe it to be the server. I use a remotefunction to handle this. I have tried SOOO many ways to try and delete these pets and it just doesnt work for me.
I send it to the client this way:
local listOfPets = {}
for petId in next, petids do
listOfPets[#listOfPets + 1] = petId -- makes it so it adds the ID to the table and not "true"
end
game.ReplicatedStorage.RemoteFunctions.Function:InvokeServer("MassDeletPets",listOfPets)
On the Server I have tried this:
if type(...) == 'table' then -- ... is variadic arguments since I use 1 remote func.
for k,m in pairs(PlayerData['petInventory']) do
if m["ID"] then -- pet GUID
local Found = false
for z,x in pairs(...) do -- returns the table just fine received from the client ( 1 GUID, 2 GUID, etc)
if rawequal(x, m['ID']) then -- x is the GUID.
Found = true
break
end
if Found == true then
PlayerData['petInventory'][k] = nil -- remove the pet index from their inventory if the id of the pet and ... table are the same.
else
print("?") -- prints the second time, and i dont know why.
end
end
end
That isn’t my only method, but just an example. I have printed/debugged a ton and came to figure it can not be the client. I’ve looped through both sides of the spectrum (server and client) and they both returned the same. e.g, 4 pets selected and sent to the server returned the same format (1 GUID, 2 GUID), etc.
Just to add on, it bugs if I don’t select EVERY pet in my inventory. I printed in my UpdatePets() function when i loop through their inventory and it looks like for example if I had 6 pets, tried to delete 4, it would print the index 5,6 and not 1,2. Doing for i = 1, #petData printed (1, nil). So I am so confused!!
If this is too long of a message, DM on discord Jaben#9847 or ask for video/screenshots. It’s hard to provide all this since it can be confusing if not written well enough