
Como fazer Inventário do Blox Fruits
Você já se perguntou como criar um sistema de inventário no estilo Blox Fruits para organizar frutas, armas e poderes no seu jogo? Então, você está no lugar certo!
No vídeo que preparei, ensino passo a passo como fazer um inventário do Blox Fruits no Roblox Studio, ideal para quem quer deixar seus jogos mais interativos e organizados. Vou explicar de forma simples como programar essa funcionalidade, criar uma interface atraente e fazer com que o sistema funcione perfeitamente no seu jogo.
Se você é fã do Blox Fruits ou quer aprender novas técnicas para seus projetos no Roblox, não perca essa aula completa! E o melhor: todos os códigos e recursos utilizados estão aqui disponíveis para você no nosso site Programação for Kids.
Não deixe de conferir e começar a criar sistemas incríveis no Roblox! 🚀
Vídeo Aula: Como fazer um inventário do Blox Fruits
Module Scripts
local ItemsTable ={
-- Frutas
[1] = {
Id = 1,
Name = "Bomba",
Type = "Fruta",
Rarity = "Comum",
Description = "Fruta simples, ideal para iniciantes.",
Damage = 100,
Image = "rbxassetid://97248243239156",
SpecialAbility = "Explosão"
},
[2] = {
Id = 2,
Name = "Chama",
Type = "Fruta",
Rarity = "Raro",
Description = "Uma fruta poderosa que permite controlar fogo.",
Damage = 500,
Image = "rbxassetid://89109421966633",
SpecialAbility = "Controle de Fogo"
},
[3] = {
Id = 3,
Name = "Dragão",
Type = "Fruta",
Rarity = "Lendário",
Description = "Transforme-se em um dragão poderoso.",
Damage = 1200,
Image = "rbxassetid://120755929632146",
SpecialAbility = "Transformação em Dragão"
},
-- Espadas
[4] = {
Id = 4,
Name = "Katana",
Type = "Arma",
Rarity = "Comum",
Description = "Uma espada básica para combate próximo.",
Damage = 150,
Image = "rbxassetid://111064284245672",
SpecialAbility = "Corte Simples"
},
[5] = {
Id = 5,
Name = "Yoru",
Type = "Arma",
Rarity = "Lendário",
Description = "Uma das espadas mais poderosas do jogo.",
Damage = 1000,
Image = "rbxassetid://71748322906457",
SpecialAbility = "Corte Sombrio"
},
-- Acessórios
[6] = {
Id = 6,
Name = "Capa do Capitão",
Type = "Acessório",
Rarity = "Raro",
Image = "rbxassetid://71748322906457",
Description = "Aumenta a resistência do jogador.",
Buffs = {
Health = 200,
Defense = 50
}
},
[7] = {
Id = 7,
Name = "Chapéu do Caçador",
Type = "Acessório",
Rarity = "Comum",
Image = "rbxassetid://97248243239156",
Description = "Melhora a precisão dos ataques à distância.",
Buffs = {
Accuracy = 15
}
}
}
return ItemsTable
Script Server
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateInventory = ReplicatedStorage.UpdateInventory
local Items = require(ReplicatedStorage:WaitForChild("ItemsModule"))
local Players = game:GetService("Players")
local FolderItens = workspace.FolderItems:GetChildren()
print(FolderItens)
local PlayerData ={}
local function EnsurePlayerData(player)
if not PlayerData[player.UserId] then
PlayerData[player.UserId]={
Inventory = {},
Coins = 0,
Level = 1,
Experience = 0
}
end
end
local function AddItemInventory(player, itemID)
EnsurePlayerData(player)
local inventory = PlayerData[player.UserId].Inventory
local itemExists = false
for _, item in ipairs(inventory) do
if item.ID == itemID then
print("ja existe")
item.Quantity = item.Quantity + 1
itemExists=true
break
end
end
if not itemExists then
print("não existe")
table.insert(inventory,{
ID = itemID,
Quantity = 1
})
end
print(inventory)
end
local debounce = false
for _, i in ipairs(FolderItens) do
i.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
local idItem = i:GetAttribute("id")
if player and not debounce then
debounce = true
i:Destroy()
print(idItem)
AddItemInventory(player, idItem)
task.wait(0.5)
UpdateInventory:FireClient(player, PlayerData[player.UserId])
task.wait(0.5)
debounce= false
end
end)
end
Players.PlayerAdded:Connect(function(player)
EnsurePlayerData(player)
end)
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateInventory = ReplicatedStorage.UpdateInventory
local ScreenGuiBtns = script.Parent.ScreenGuiBtns
local BtnClose = ScreenGuiBtns.Frame.BtnClose
local BtnItens = ScreenGuiBtns.Frame.BtnItens
local Items = require(ReplicatedStorage:WaitForChild("ItemsModule"))
print(Items)
local results = {}
local ImageItem = ReplicatedStorage.ImageItem
local UIGrid = ReplicatedStorage.UIGridLayout
local ScreenMenu = script.Parent.ScreenMenu
local BtnMenu = ScreenMenu.Frame.BtnMenu
local ScreenInventario = script.Parent.ScreenInventario
local ScroolingFrame = ScreenInventario.FrameContainer.ScrollingFrame
local FrameContainer = ScreenInventario.FrameContainer
local FrameDetails = FrameContainer.FrameDetails
local BtnCloseInventario = FrameContainer.BtnClose
local FrameSearch = FrameContainer.FrameSearch
local TextBox = FrameSearch.TextBox
FrameContainer.Visible = false
FrameDetails.Visible = false
local function updateInventory(data)
local itemIds ={}
for _, i in ipairs(data) do
local existingItem = ScroolingFrame:FindFirstChild(i.id)
if existingItem then
existingItem.TextQtd.Text = i.quantity
else
local item = ImageItem:Clone()
item.Parent = ScroolingFrame
if not ScroolingFrame:FindFirstChild("UIGridLayout") then
local UiGridLayout = UIGrid:Clone()
UiGridLayout.Parent = ScroolingFrame
end
item.Name= i.id
item.ImageButton.ZIndex = 1
item.ImageButton.Image= i.image
item.NameText.Text= i.name
item.TypeText.Text = i.types
item.TypeText.ZIndex =2
item.TextQtd.Text = i.quantity
item.Visible= true
item.ImageButton.MouseButton1Click:Connect(function()
FrameDetails.Visible=true
FrameDetails.TextName.Text = i.name
FrameDetails.ImageLabel.Image = i.image
FrameDetails.TextType.Text = i.types
FrameDetails.TextLabel.Text= i.description
end)
itemIds[i.id]=true
end
end
end
local function getInventoy()
local inventory ={}
for _,i in ipairs(results) do
for _, j in ipairs(Items)do
if i.ID== j.Id then
local itemInfo={
name = j.Name,
quantity= i.Quantity,
image= j.Image,
description = j.Description,
id= j.Id,
rarity = j.Rarity,
types = j.Type
}
table.insert(inventory, itemInfo)
end
end
end
return inventory
end
local function searchInventory(data, word)
ScroolingFrame:ClearAllChildren()
for _,i in ipairs(data) do
if string.find(i.name:lower(), word) then
local item:Frame = ImageItem:Clone()
item.Parent = ScroolingFrame
item.Name = i.id
item.ImageButton.Image = i.image
item.NameText.Text= i.name
item.NameText.ZIndex= 2
item.TypeText.Text = i.types
item.TypeText.ZIndex=2
item.TextQtd.Text= i.quantity
item.Visible=true
item.ImageButton.MouseButton1Click:Connect(function()
FrameDetails.Visible=true
FrameDetails.TextName.Text = i.name
FrameDetails.ImageLabel.Image = i.image
FrameDetails.TextType.Text = i.types
FrameDetails.TextLabel.Text= i.description
end)
end
end
end
BtnMenu.MouseButton1Click:Connect(function()
ScreenMenu.Enabled = false
ScreenGuiBtns.Enabled = true
end)
BtnClose.MouseButton1Click:Connect(function()
ScreenMenu.Enabled = true
ScreenGuiBtns.Enabled = false
end)
BtnItens.MouseButton1Click:Connect(function()
ScreenInventario.Enabled=true
ScreenGuiBtns.Enabled = false
--ScreenInventario.Visible = true
FrameContainer.Visible = true
end)
BtnCloseInventario.MouseButton1Click:Connect(function()
ScreenInventario.Enabled=false
ScreenGuiBtns.Enabled = true
--ScreenInventario.Visible = false
FrameContainer.Visible = false
end)
TextBox.Changed:Connect(function(t)
if t=="Text" then
local searchTerm= TextBox.Text:lower()
if searchTerm=="" then
local dataItens = getInventoy()
updateInventory(dataItens)
else
local dataItens = getInventoy()
searchInventory(dataItens,searchTerm)
end
end
end)
UpdateInventory.OnClientEvent:Connect(function(data)
print("Recebi do Server")
print(data)
results = data.Inventory
local dataItens = getInventoy()
print(dataItens)
updateInventory(dataItens)
end)