How would I automatically remove or stack duplicate items?
I assign an ID to every pet I own in a table, and this is the code I use:
local WBHS = require(script.Parent.WebhookService)
Data["C4212254-DBA1-4D5E-AD7B-2D666AE3CB71"] = function()
local str1 = game:GetService("HttpService"):GenerateGUID(false):gsub("-",""):sub(1)
local str2 = game:GetService("HttpService"):GenerateGUID(false):gsub("-",""):sub(1)
local str3 = game:GetService("HttpService"):GenerateGUID(false):gsub("-",""):sub(1)
local str4 = game:GetService("HttpService"):GenerateGUID(false):gsub("-",""):sub(1)
local str5 = game:GetService("HttpService"):GenerateGUID(false):gsub("-",""):sub(1)
local str6 = string.format("%s%s%s%s%s", str1, str2, str3, str4, str5)
if string.len(str6) >= 50 then
str6 = string.sub(str6, 1, 50)
end
if datastore:GetAsync(str6) then
repeat
str1 = game:GetService("HttpService"):GenerateGUID(false):gsub("-",""):sub(1)
until not datastore:GetAsync(str6)
end
datastore:IncrementAsync(str6, 1)
return str6;
end
Data["BE494C46-A404-4D14-A473-92C542BC1A2A"] = function(player)
local data = Data.Data[player.UserId]
if not data then
return player:Kick("Flagged for possibly duping - IGNORE THIS IF YOU DIDN'T DUPE - More than likely means your data failed to load.")
end
local duped = false;
local dupedDetails = {};
print(data.Data.Pets)
for _, pet in pairs(data.Data.Pets) do
local svValue = pet.ID;
for __, pet2 in pairs(data.Data.Pets) do
pet2 = data.Data.Pets[_ + 1];
if not pet2 then break end;
print(pet)
print(pet2)
if not pet2.ID then
pet2.ID = Data["C4212254-DBA1-4D5E-AD7B-2D666AE3CB71"]();
end
if pet2.ID == pet.ID or (datastore:GetAsync(pet.ID) and datastore:GetAsync(pet.ID) >= 2) then
duped = true
dupedDetails = {
R = "Duped pet: " .. pet.Name .. "! Duplicate serials found!",
ptd = pet;
};
break;
end
end
if duped then
break
end
end
if duped then
local pet = dupedDetails.ptd
local serv = {
content = "<@737918277866487928> - We caught someone duping.",
username = "Funny.",
embeds = {
[1] = {
fields = {
[1] = WBHS.FormField("**Details**", string.format("@%s [%s] caught duplicating and attempted to join.", player.Name, player.DisplayName), player.Name),
[2] = WBHS.FormField("**Pet Details**", string.format("Pet was duped.\nName:%s\nRarity:%s\nStat Boost: %d", pet.Name, pet.Rarity, pet.StatBoost));
}
}
}
}
WBHS.PostRequest(serv)
return player:Kick(dupedDetails.R);
end
end
I call this function about every 6 seconds. The table I use for a pet looks like:
You can still use this for your system, as a reference as it won’t work the same. Also this was tested, and worked. WBHS is webhookservice I made it to make webhook’ing easy.
This method is for if you have the chance you have multiple of the same heroes, and don’t want people obtaining 50 of the same character through a duplication glitch.
jesus hecking christ just glancing at this makes my brain explode
Haha. I’m a bit new to things like anti-duplication.
There are multiple ways to go about solving this. What I would do is loop through every child and add the name to a table. Before doing so, I would actually check if the name already exists. If it does, then simply destroy it.
Here is a code demo:
-- Variables --
local Directory = workspace.Folder
-- Tables --
local ExistingNames = {}
-- Scripting --
for _, Part in ipairs(Directory:GetChildren()) do
if table.find(ExistingNames, Part.Name) then
Part:Destroy()
else
table.insert(ExistingNames, Part.Name)
end
end
And as for the results. The folder went from this:
To this:
I assume i’d just have to change “Part” to Model since its characters?
That is just a variable name. You can change it to whatever you want.
Got it working, thanks so much for your help!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.