Roblox lua ile oyuna giren kişinin envanterini listeleten bir kod var bu kodu bir…
- User
Roblox lua ile oyuna giren kişinin envanterini listeleten bir kod var bu kodu bir function haline getiirp envanteri listelenen kişinin envanterini yeni veriler tekarr yenilemesi lazım. Eski itemleri silsin lakin itemTemplate silinmesin kopyalama işlemleri onun üzerinden yapılır.
for kodu:
Players.PlayerAdded:Connect(function(player) -- Oyuncunun karakterinin tamamen yüklendiğinden emin olun player.CharacterAdded:Wait()
-- GUI öğelerine ulaşmak için PlayerGui'yi bekleyin local playerGui = player:WaitForChild("PlayerGui") local menus = playerGui:WaitForChild("Menus") local inventoryMenu = menus:WaitForChild("InventoryMenu") local mainFrame = inventoryMenu:WaitForChild("MainFrame") local scrollingFrame = mainFrame:WaitForChild("ScrollingFrame") -- Şablon olan Item frame'ini bul local itemTemplate = scrollingFrame:WaitForChild("Item") -- Envanterdeki itemleri al local inventory = Inventory.getInventory(player) print(inventory) -- Envanterdeki toplam item sayısını hesaplayın local totalItems = 0 for _ in pairs(inventory) do totalItems = totalItems + 1 end -- Envanterdeki toplam item sayısını StatsBackground altında gösterin local statsBackground = mainFrame:WaitForChild("StatsBackground") local inventorySpace = statsBackground:WaitForChild("InventorySpace") local totalItemsLabel = inventorySpace:WaitForChild("TextLabel") -- Toplam item sayısını TextLabel'e yazdırın totalItemsLabel.Text = tostring(totalItems) -- Envanterdeki her bir item için işlemleri yap for itemId, itemData in pairs(inventory) do -- Item şablonunu çoğalt local item_id = itemData.item_type local item_info = ItemsConfig:GetItem(item_id) local newItem = itemTemplate:Clone() newItem.Parent = scrollingFrame newItem.Visible = true -- Görünür yap (şablon başlangıçta gizli olabilir) --Statlar-- local HarvestGain_stat = newItem:FindFirstChild("stats1") local FarmIncome_stat = newItem:FindFirstChild("stats2") local HarvestSpeed_stat = newItem:FindFirstChild("stats3") if item_info.Type == "scythe" then HarvestGain_stat.Visible = true HarvestSpeed_stat.Visible = true local nameLabel = newItem:FindFirstChild("Frame"):FindFirstChild("icons"):FindFirstChild("Name") --local levelLabel = newItem:FindFirstChild("Frame"):FindFirstChild("icons"):FindFirstChild("Frame"):FindFirstChild("Frame"):FindFirstChild("Price") local HarvestGain = newItem:FindFirstChild("stats1"):FindFirstChild("Stat1") local HarvestSpeed = newItem:FindFirstChild("stats3"):FindFirstChild("Stat3") -- İtem bilgilerini UI elemanlarına ekle if nameLabel and nameLabel:IsA("TextLabel") then nameLabel.Text = item_info.Name -- İtemin ismini ayarla end if HarvestGain and HarvestGain:IsA("TextLabel") then HarvestGain.Text = item_info.Harvest_Gain.."x" -- İtemin ismini ayarla end if HarvestSpeed and HarvestSpeed:IsA("TextLabel") then HarvestSpeed.Text = item_info.Harvest_Speed.."x" -- İtemin ismini ayarla end elseif item_info.Type == "pet" then HarvestGain_stat.Visible = true FarmIncome_stat.Visible = true local nameLabel = newItem:FindFirstChild("Frame"):FindFirstChild("icons"):FindFirstChild("Name") --local levelLabel = newItem:FindFirstChild("Frame"):FindFirstChild("icons"):FindFirstChild("Frame"):FindFirstChild("Frame"):FindFirstChild("Price") local HarvestGain = newItem:FindFirstChild("stats1"):FindFirstChild("Stat1") local FarmIncome = newItem:FindFirstChild("stats3"):FindFirstChild("Stat3") -- İtem bilgilerini UI elemanlarına ekle if nameLabel and nameLabel:IsA("TextLabel") then nameLabel.Text = item_info.Name -- İtemin ismini ayarla end if HarvestGain and HarvestGain:IsA("TextLabel") then HarvestGain.Text = item_info.Harvest_Gain+"x" -- İtemin ismini ayarla end if FarmIncome and FarmIncome:IsA("TextLabel") then FarmIncome.Text = item_info.Harvest_Speed+"x" -- İtemin ismini ayarla end elseif item_info.Type == "pot" then HarvestGain_stat.Visible = true FarmIncome_stat.Visible = true local nameLabel = newItem:FindFirstChild("Frame"):FindFirstChild("icons"):FindFirstChild("Name") --local levelLabel = newItem:FindFirstChild("Frame"):FindFirstChild("icons"):FindFirstChild("Frame"):FindFirstChild("Frame"):FindFirstChild("Price") local HarvestGain = newItem:FindFirstChild("stats1"):FindFirstChild("Stat1") local FarmIncome = newItem:FindFirstChild("stats3"):FindFirstChild("Stat3") -- İtem bilgilerini UI elemanlarına ekle if nameLabel and nameLabel:IsA("TextLabel") then nameLabel.Text = item_info.Name -- İtemin ismini ayarla end if HarvestGain and HarvestGain:IsA("TextLabel") then HarvestGain.Text = item_info.Harvest_Gain+"x" -- İtemin ismini ayarla end if FarmIncome and FarmIncome:IsA("TextLabel") then FarmIncome.Text = item_info.Harvest_Speed+"x" -- İtemin ismini ayarla end end -- Item ismi ve seviyesi için TextLabel öğelerini bul -- Rarity'e göre arka plan rengini ayarla local itemFrame = newItem:FindFirstChild("Frame") if itemFrame and itemFrame:IsA("ImageButton") then local rarity = item_info.Rarity or "Common" -- Default olarak "Common" itemFrame.BackgroundColor3 = rarityColors[rarity] or Color3.fromRGB(169, 169, 169) -- Rarity bulunamazsa gri (Common) renk uygula end --if levelLabel and levelLabel:IsA("TextLabel") then -- levelLabel.Text = tostring(itemData.item_level) -- İtem seviyesini ayarla --end -- Yeni item görünür hale getirildi. newItem.Visible = true end - Assistant