The Script is supposed to remove all gears but loop through the once that are also percent in the StarterPack and check if there are duplicates. If so then delete the duplicate, I suspect there’s a Problem with how I made the loop.
The problem is that it doesn’t delete every duplicate. Neither does it even Check Them.
This is what printed in the Video, The first lines are HD admin.
15:09:55.000 💧 [NEW!] Water Bottle Tycoon 💧 auto-recovery file was created - Studio
15:09:55.763 Requiring asset 3239236979.
Callstack:
ServerScriptService.HD Admin.Settings.Loader, line 13
- Server - Loader:13
15:10:10.007 ClassicSword SusSword false - Server - GearRemover:186
15:10:10.007 ClassicSword BlueHyperlaserGun false - Server - GearRemover:186
15:10:10.007 ClassicSword RedHyperLaser false - Server - GearRemover:186
15:10:10.007 ▶ ClassicSword BlueHyperlaserGun false (x6) - Server - GearRemover:186
15:10:10.008 BlueHyperlaserGun SusSword false - Server - GearRemover:186
15:10:10.008 BlueHyperlaserGun RedHyperLaser false - Server - GearRemover:186
15:10:10.008 ▶ BlueHyperlaserGun BlueHyperlaserGun true (x3) - Server - GearRemover:186
15:10:10.008 BlueHyperlaserGun SusSword false - Server - GearRemover:186
15:10:10.008 ▶ BlueHyperlaserGun BlueHyperlaserGun false (x2) - Server - GearRemover:186
15:10:10.009 BlueHyperlaserGun BlueHyperlaserGun true - Server - GearRemover:186
This is the script. I’ve tried documenting everything as clear as possible. Ask if anything need further explanation! It shouldn’t be too hard to figure out what the script does even tough you don’t know OOP.
It’s Just Very Long. And Complicated.
Feel Free To Copy This Whole Script Or Functions For Use In Your Own Game!
local Players = game:GetService("Players")
local StarterPack = game:GetService("StarterPack")
--// CDT = Content Data Type (Mesh Id )
local CDT1 = "rbxassetid://"
local CDT2 = "https://www.roblox.com/asset/?id="
--// Returns shortened MeshId or nil if invalid:
local function GetMeshIdNumS(MeshId)
if string.find(MeshId, CDT1) then
MeshId = string.gsub(MeshId, CDT1, "")
elseif string.find(MeshId, CDT2) then
MeshId = string.gsub(MeshId, CDT2, "")
else return end
local MeshIdNum = tonumber(MeshId)
if MeshIdNum == nil then return end
return MeshIdNum
end
--// Returns Shotened MeshId from Mesh or nil:
local function GetMeshIdNum(Handle)
local MeshId
if Handle:IsA("MeshPart") then
MeshId = Handle.MeshId
else
local Mesh = Handle:FindFirstChildWhichIsA("SpecialMesh") or
Handle:FindFirstChildWhichIsA("BlockMesh")
MeshId = Mesh.MeshId
end
MeshId = GetMeshIdNumS(MeshId)
return MeshId
end
--// Returns Handle or nil if absent
local function GetHandle(Tool)
local Handle = Tool:FindFirstChild("Handle")
if Handle == nil then return end
return Handle
end
local function CheckTools(Tool, OtherTool)
if Tool.Name ~= OtherTool.Name then return false end
local ToolHandle = GetHandle(Tool)
local OtherToolHandle = GetHandle(OtherTool)
--// Requires Handle
if ToolHandle == nil and OtherToolHandle ~= nil then return false end -- First Absent and second not
if OtherToolHandle == nil and ToolHandle ~= nil then return false end -- Second Absent and First not
--// Mesh Id Check
local ToolMeshIdNum = GetMeshIdNum(ToolHandle)
if ToolMeshIdNum == nil then return false end -- Invalid Mesh or MeshId
local OtherToolMeshIdNum = GetMeshIdNum(OtherToolHandle)
if OtherToolMeshIdNum == nil then return false end
--// Not Same Mesh
if ToolMeshIdNum ~= OtherToolMeshIdNum then return false end
return true
end
local GearRemover = {}
GearRemover.__index = GearRemover
function GearRemover.new(Tycoon, instance)
local self = setmetatable({}, GearRemover)
self.Tycoon = Tycoon
self.Instance = instance
self.Hitter = instance.Hitter
self.ClickDetector = instance.Hitter.ClickDetector
return self
end
function GearRemover:Init()
self.Hitter.Touched:Connect(function(...)
self:OnHit(...)
end)
self.ClickDetector.MouseClick:Connect(function(...)
self:OnClick(...)
end)
end
function GearRemover:OnClick(Player)
local Hitter = self.Hitter
if Hitter.CanTouch == false then return end
Hitter.CanTouch = false
local Character = Player.Character
if Character == nil then return end
self:RemoveGears(Player, Character)
task.wait(1)
Hitter.CanTouch = true
end
function GearRemover:OnHit(Hit)
local Hitter = self.Hitter
Hitter.CanTouch = false
local Character = Hit.Parent
local Player = Players:GetPlayerFromCharacter(Character)
self:RemoveGears(Player, Character)
task.wait(2)
Hitter.CanTouch = true
end
function GearRemover:RemoveGears(Player, Character)
if Player == nil then return end
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid == nil then return end
if Humanoid:GetState() == Enum.HumanoidStateType.Dead then return end
if Humanoid.Health <= 0 then return end
Humanoid:UnequipTools()
local Backpack = Player:FindFirstChild("Backpack")
if Backpack == nil then return end
local StarterPacks = {}
local RemovableTools = {}
for _, Tool in ipairs(Backpack:GetChildren()) do
if StarterPack:FindFirstChild(Tool.Name) then -- in StarterPack
table.insert(StarterPacks, Tool)
else
table.insert(RemovableTools, Tool)
end
end
for _, Tool in ipairs(RemovableTools) do -- Destroys non-Starterpack
Tool:Destroy()
end
for i, Tool in ipairs(StarterPacks) do -- Destroys Duplicates [PROBLEM HERE]
local NewStarter = StarterPacks
table.remove(NewStarter, i)
local Destroyables = {}
for j, OtherTool in ipairs(NewStarter) do
local Result = CheckTools(Tool, OtherTool)
print(Tool.Name, OtherTool.Name, Result)
if Result == true then
table.remove(StarterPacks, i)
table.insert(Destroyables, OtherTool)
end
end
for _, Destroyable in ipairs(Destroyables) do
Destroyable:Destroy()
end
end
end
return GearRemover
Ye and the script is also quite inefficient.