Hello!
I have got a script where it sets a price for the item.
But the price is multiplied by exactly 23.
I think the reason in this because the table that the script is looping has 23 content in it (so 23 values in the table.)
I don’t know how to fix it though.
Also I did print the item cost and printed the original cost 23 times, I think it adds them all together and the price is the sum.
Any solutions? Thanks in advance
Loop:
SellBTN.MouseButton1Click:Connect(function(plr)
local tools = player.Character:GetChildren()
local equippedTool = character:FindFirstChildWhichIsA("Tool")
if equippedTool then
for i, toolSin in ipairs(tools) do
for _, item in ipairs(Items) do
if equippedTool.Name == item.Name then
print(item.Cost)
Price = item.Cost
end
end
print(Price) -- Price is looping BUG
--ServerSelling:FireServer(Price)
Price = 0
equippedTool:Destroy()
end
end
end)
Table:
local Items = {
{Name = "Newspaper", Cost = 3, Rarity = "Common"},
{Name = "Rat", Cost = 2, Rarity = "Common"},
{Name = "Broken Furniture", Cost = 70, Rarity = "Legendary"},
{Name = "Toy", Cost = 8, Rarity = "Uncommon"},
{Name = "Bottle", Cost = 3, Rarity = "Common"},
{Name = "Shoes", Cost = 13, Rarity = "Rare"},
{Name = "Monitor", Cost = 85, Rarity = "Legendary"},
{Name = "Scrap Metal", Cost = 2, Rarity = "Common"},
{Name = "Clothes", Cost = 10, Rarity = "Uncommon"},
{Name = "Cardboard", Cost = 4, Rarity = "Common"},
{Name = "Book", Cost = 4, Rarity = "Common"},
{Name = "Plastic Container", Cost = 7, Rarity = "Uncommon"},
{Name = "Food Scraps", Cost = 13, Rarity = "Uncommon"},
{Name = "Hammer", Cost = 30, Rarity = "Rare"},
{Name = "Can", Cost = 3, Rarity = "Common"},
{Name = "Magazines", Cost = 12, Rarity = "Uncommon"},
{Name = "Dishes", Cost = 27, Rarity = "Rare"},
{Name = "Batteries", Cost = 25, Rarity = "Rare"},
{Name = "Desk", Cost = 115, Rarity = "Legendary"},
{Name = "Chair", Cost = 43, Rarity = "Rare"},
{Name = "Keyboard", Cost = 58, Rarity = "Legendary"},
{Name = "Light", Cost = 43, Rarity = "Legendary"},
{Name = "PC", Cost = 468, Rarity = "Mythic"},
{Name = "Fridge", Cost = 324, Rarity = "Mythic"},
{Name = "Microwave", Cost = 286, Rarity = "Mythic"},
{Name = "Paint Brush", Cost = 11, Rarity = "Uncommon"},
{Name = "Paint Can", Cost = 7, Rarity = "Uncommon"},
}