Roblox studio ile bir oyun geliştiriyorum burada bir envanter ui ımız mevcut. Sana ui a…
- User
Roblox studio ile bir oyun geliştiriyorum burada bir envanter ui ımız mevcut. Sana ui a nasıl veri eklediğimin kodunu atacağım ve ihtiyacımız olan şeyi yazacağım. Envanter için update functionuna ihtiyacımız var envanter yeni bir veri eklendiğinde (addItemToInventory) bu envanter yenilenmeli dilersen tüm itemları silip yeniden oluşturabilirsin
-
kod örneği oyuncu oyuna girdiğinde datastore üzerinden envanteri verilerini çekip ui a ekleyen yapı yolu: ServerScriptservice->Inventory->main(Script) 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 itemFrame2 = scrollingFrame:WaitForChild("Item") local itemTemplate = itemFrame2:WaitForChild("Frame")
-- Envanterdeki itemleri al local inventory = Inventory.getInventory(player, 1) 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 = itemFrame2 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.Farm_Income.."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 -- Yeni item görünür hale getirildi. newItem.Visible = true
-
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.