-
What do you want to achieve?
Within this function, I want it to check to see whether all of items within the slots each have a certain level AND are a specific type. It doesn’t matter the order of how the player puts them into the slots, just that each item has a specific level. For example, one item has a Level.Value = 1, one item has a Level.Value = 2, one item has a Level.Value = 3, and one item has a Level.Value = 4. If this condition is met, then when they press the UpgradeButton, the slots will be cleared and the items that they inserted into the slots will be removed from their inventory. If the condition is not met, then nothing will happen. -
What is the issue?
When I press the UpgradeButton, the items aren’t being removed from the player’s inventory AND it’s printing this (see photo below) which means that it’s false… but it’s actually NOT false because the items DO meet the Level requirementsAdditionally, it puts the items back into the Items frame/grid, even though they’re also still being displayed in the slots.
-
What solutions have you tried so far?
I’ve literally spent hours trying to fix my code and it still is not working… nothing online helps either ):
--Variables--
local DataFolder = game.Players.LocalPlayer:WaitForChild('Data_Folder')
local SettingsFolder = script.Parent.Parent.Parent.Parent:WaitForChild('GameInventory').Frame.Inventory.Settings
local ForgeFrame = script.Parent.ForgeFrame
local UpgradeButton = script.Parent.ForgeFrame.UpgradeButton
local OpenEvent = game.ReplicatedStorage.UpgradeEvents.OpenTradeUI -- create RE
local UpgradeCard = game.ReplicatedStorage.UpgradeEvents.SubmitArtifacts -- create RE
local ItemGrid = script.Parent.Items.Grid
local InvGrid = script.Parent.Parent.Parent.Parent.GameInventory.Frame.Inventory.Items.Grid
local Events = game.ReplicatedStorage.InvEvents
local Available = ForgeFrame.Slots.Available --// Holds the value of the first available slot
...
local function upgradeCard()
print("UpgradeCard funct")
local levels = {} -- Empty table to track levels
-- Check for cards with the required levels in the slots
for level = 1, 4 do
local cardFound = false -- Flag to track if a card with the required level is found
-- Iterate over the Slots and check for cards with the required level
for _, slot in ipairs(Slots) do
local item = slot.ViewportFrame.Model:FindFirstChildWhichIsA('Model')
if item and item:FindFirstChild("Level") and item.Level.Value == level then
cardFound = true
break
end
end
table.insert(levels, cardFound) -- Store whether a card with the required level was found
end
-- Check if all required levels are filled
local allLevelsFilled = true
for _, filled in ipairs(levels) do
if not filled then
allLevelsFilled = false
break
end
end
print("Levels:", table.unpack(levels))
print("allLevelsFilled:", allLevelsFilled)
if allLevelsFilled then
-- Remove items from the player's inventory and update SettingsFolder
for _, slot in ipairs(Slots) do
local item = slot.ViewportFrame.Model:FindFirstChildWhichIsA('Model')
if item then
print("Removing", item.Name, "with Level", item.Level.Value)
removeCard(slot)
Events.RemoveFromInv:FireServer(item)
script.UpgradeSound:Play()
end
end
SettingsFolder.CurrentArtStorage.Value = SettingsFolder.CurrentArtStorage.Value - 4 -- Decrease the value by 4
Available.Value = 1
print("Items removed from the player's inventory.")
print("SettingsFolder.CurrentArtStorage.Value decreased by 4.")
for _, slot in ipairs(Slots) do
local viewportFrame = slot.ViewportFrame
slot.Occupied.Value = ''
local model = viewportFrame.Model:FindFirstChildWhichIsA('Model')
if model then model:Destroy() end
end
else
print("Please fill all slots with the required levels.")
end
end
...
...
--Events--
OpenEvent.OnClientEvent:Connect(function(itemType)
script.Parent.Parent.Visible = true
selectedType = itemType
updateList()
end)
for _, slot in ipairs(Slots) do
slot.Activated:Connect(function()
if slot.Occupied.Value ~= '' and slot.Occupied.Value ~= nil then
if slot.ViewportFrame.Model:FindFirstChildOfClass('Model') then
removeCard(Slots[Available.Value - 1])
end
end
end)
slot.Text = slot.Occupied.Value
slot.Occupied.Changed:Connect(function(value)
slot.Text = value
end)
end
Available.Changed:Connect(function(value)
if value == 1 then
for _, tab in ipairs(ItemGrid:GetChildren()) do
if tab:IsA('Frame') then
tab.Visible = true
end
end
end
end)
UpgradeButton.Activated:Connect(function()
upgradeCard(Slots[1].Occupied.Value)
task.wait(0.1)
updateList()
end)
game.ReplicatedStorage.UpgradeEvents.OpenTradeUI.OnClientEvent:Connect(function(itemType)
if DataFolder.CurrentArtStorage.Value ~= (#ItemGrid:GetChildren() - 1) then
selectedType = itemType
updateList()
end
end)
task.wait(3)
updateList()
PLEASE let me know if you’d like to include any more additional information!!!