Hello! I am trying to make an rng type game where you roll and add items to your inventory. The rolling system works, but when you go to claim it, the item often gives you a different item from the same rarity, or a duplicate.
as you can see, I claim one item from the epic tier and it gives me every item in that tier. But, it only appears to do that if you have been rolling for a while. So it does’nt happen on your first role.
Here is my code:
local function addToInventory(character)
local characterName = character.Name
print("Adding to inventory: " .. characterName)
if inventory[characterName] then
inventory[characterName].Quantity = inventory[characterName].Quantity + 1
inventory[characterName].Label.Text = "X" .. inventory[characterName].Quantity
print("Updated quantity for: " .. characterName .. " to " .. inventory[characterName].Quantity)
else
print("Cloning template for new item: " .. characterName)
local newTemplate = template:Clone()
newTemplate.Parent = script.Parent.Parent.Inventory.ScrollingFrame
newTemplate.WorldModel:ClearAllChildren()
local worldModel = newTemplate:FindFirstChild("WorldModel")
if not worldModel then
worldModel = Instance.new("WorldModel")
worldModel.Parent = newTemplate
end
local characterClone = character:Clone()
characterClone.Parent = worldModel
local camera = Instance.new("Camera")
camera.Parent = newTemplate
newTemplate.CurrentCamera = camera
local humanoidRootPart = characterClone:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
camera.CFrame = CFrame.new(humanoidRootPart.Position + Vector3.new(4, 2, 0), humanoidRootPart.Position)
end
newTemplate.NameLabel.Text = characterName
newTemplate.QuantityLabel.Text = "x1"
newTemplate.Visible = true
inventory[characterName] = {
Quantity = 1,
Label = newTemplate.QuantityLabel
}
print("Added new item to inventory: " .. characterName)
end
end
NOTE: The characters are located in folders inside of replicated storage.
I can’t seem to find out what the issue is. If you need me to provide more code I can.
Any help is apreciated!