Hello, I’ll need for a help. I’m wondering how I can prevent duplicate items within the same folder. I’m currently working on a RNG game… I can’t fix simple issues with my coding block, this the only way i’ll could find help. I tried everything it’s still doesn’t works
Module Script
local module = {}
--[[local function hasItem(folder, itemToFind)
for _, item in ipairs(folder:GetChildren()) do
if item.Name == itemToFind then
return true
end
end
return false
end]]
function module.Aura(character, plr)
local AurasFolder = game.ServerStorage:WaitForChild('Auras')
local AurasInventories = character:WaitForChild('AURAS')
local rolls = plr:FindFirstChild("leaderstats").Aura
if not AurasFolder then return end
for i, v in pairs(AurasFolder:GetChildren()) do
if rolls.Value == v.Name then -- check the roll value has a same name as the folder
local auraClone = v:Clone() -- clone the folder
auraClone.Parent = AurasInventories -- parented to aurainventories
for i2, v2 in pairs(v:GetChildren()) do
local root = character:FindFirstChild(v2.Name)
if root then
local auraBase = v2:Clone()
auraBase.Parent = root
auraBase.CanCollide = false
auraBase.Massless = true
local weld = Instance.new("Weld", auraBase)
weld.Part0 = root
weld.Part1 = auraBase
end
end
end
end
end
function module.AuraUnequipped(character, plr)
local AurasInventories = character:WaitForChild('AURAS')
for _, child in pairs(character:GetChildren()) do
for _, secondChild in pairs(child:GetChildren()) do
if secondChild.Name == child.Name then
secondChild:Destroy()
end
end
end
for _, child in pairs(AurasInventories:GetChildren()) do
if child:IsA("Folder") then
child:Destroy()
end
end
end
return module
Server
local rp = game:GetService("ReplicatedStorage")
local aurasModule = require(game.ReplicatedStorage:WaitForChild("AurasModule"))
local rollevent = rp:WaitForChild('RollEvent')
local unequippedAura = rp:WaitForChild('Unequipped')
local Chances = {
{"Dice", 1};
{"Death", 2};
{"Deceased", 4};
}
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "leaderstats"
local rolls = Instance.new("IntValue", folder)
rolls.Name = "Rolls"
rolls.Value = 0
local AuraName = Instance.new("StringValue", folder)
AuraName.Name = "Aura"
AuraName.Value = "None"
plr.CharacterAdded:Connect(function(char)
local AURAChar = Instance.new("Folder", char)
AURAChar.Name = "AURAS"
end)
end)
local function Rarity(user)
local totalValue = 1
for index, Value in pairs(Chances) do
if math.random(1, Value[2]) == 1 and Value[2] >= Chances[totalValue][2] then
totalValue = index
end
end
user:FindFirstChild("leaderstats").Rolls.Value += 1
return totalValue
end
rollevent.OnServerInvoke = function(plr)
local character = plr.Character or plr.CharacterAdded:Wait()
local chances = Chances[Rarity(plr)][1]
plr:FindFirstChild("leaderstats").Aura.Value = chances
aurasModule.Aura(character, plr)
return chances
end
unequippedAura.OnServerInvoke = function(plr)
local character = plr.Character or plr.CharacterAdded:Wait()
aurasModule.AuraUnequipped(character, plr)
end