Hello, so I’ve been creating a Inventory system lately, though it hasn’t been going well. Cutting to the chase, the “gloveTable” table is not returned when doing so.
As a result, I continuously get debugPrints from the console.
I’ve been trying to fix the issue for about 3 hours to no avail. Got desperate, and started searching online to also no avail, so now I am making a post for this.
If you have any info or solution on how to solve this, it would be very appreciated!
Server
local PlayersService = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local BadgeService = game:GetService("BadgeService")
local ServerStorage = game:GetService("ServerStorage")
local GlovesFol = ServerStorage:FindFirstChild("AvailableGloves")
local Events = ReplicatedStorage:WaitForChild("Events")
local Functions = Events:WaitForChild("Functions")
local Remotes = Events:WaitForChild("Remotes")
local Do_Debug = true
local function debugPrint(...)
if Do_Debug then
print("[DEBUG]", ...)
end
end
local function getCurrentGloves(...)
local args = {...}
local validation = args[2]
if validation ~= "01_Validation" then
debugPrint("nonvalid authorization received:", validation)
return {}
end
local glovesTable = {}
for _, v in pairs(GlovesFol:GetChildren()) do
if v:IsA("Tool") then
table.insert(glovesTable, v)
end
end
if #glovesTable == 0 then
warn("Error; no gloves found in GlovesFol")
else
debugPrint("available gloves found:", #glovesTable)
end
return glovesTable
end
local function meetsRequirements(player, glove)
local reqType = glove:GetAttribute("ReqType")
local statRequirement = glove:GetAttribute("CostAmt")
local badgeID = glove:GetAttribute("BadgeID")
local passID = glove:GetAttribute("PassID")
if reqType == "Stat" then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats and leaderstats:FindFirstChild("Glove") then
return leaderstats.Glove.Value >= statRequirement
end
elseif reqType == "Badge" then
return BadgeService:UserHasBadgeAsync(player.UserId, badgeID)
elseif reqType == "Pass" then
return MarketplaceService:UserOwnsGamePassAsync(player.UserId, passID)
end
return false
end
local function changeGlove(...)
local args = {...}
local player = args[1]
local gloveName = args[2]
local validation = args[3]
if not (player and gloveName and validation == "01_Validation") then return false end
local glove = GlovesFol:FindFirstChild(gloveName)
if not glove then debugPrint("glove not found:", gloveName) return false end
if not meetsRequirements(player, glove) then
return false
end
local leaderstats = player:FindFirstChild("leaderstats")
local stat = leaderstats:FindFirstChild("Glove")
if not leaderstats or not stat then return false end
stat.Value = gloveName
local character = player.Character or player.CharacterAdded:Wait()
if not character then debugPrint("char not found for player:", player.Name) return false end
character:LoadCharacter()
local RemoteFunction = Functions:WaitForChild("EquipGloveFunction")
RemoteFunction:Invoke(player, gloveName, "equipping_true")
player.CharacterAdded:Once(function(newCharacter)
local SpawnFol = workspace.Maps.Arena.Spawns
local chosenSpawn = SpawnFol:GetChildren()[math.random(1, #SpawnFol:GetChildren())]
newCharacter:WaitForChild("HumanoidRootPart").CFrame = chosenSpawn.CFrame
end)
debugPrint("successfully changed glove to:", gloveName, player)
return true
end
Functions.GetAvailableGloves.OnServerInvoke = function(...)
return getCurrentGloves(...) or false
end
Remotes.ChangeGloveEvent.OnServerEvent:Connect(changeGlove)
Client
local PlayersService = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local LocalPlayer = PlayersService.LocalPlayer
local UI = script.Parent.Parent
local MainFrame = UI:WaitForChild("MainFrame")
local InventoryFrame = MainFrame:WaitForChild("OpenFramesHolder"):WaitForChild("InventoryFrame")
local Contents = InventoryFrame:WaitForChild("ContentsFrame")
local ScrollingFrame = Contents.ClippingFrame.ScrollingFrame -- holds frames
local SearchBox = Contents.SearchBox -- search gloves
local utilMod = require(script.MainModule) -- handles searching functions
local SelectFrame = Contents.SelectFrame
local ShownName = SelectFrame.GloveName
local SelViewport = SelectFrame.Viewport
local ConfirmBtn = SelectFrame.EquipBtn
local FeedText = Contents.InfoText
local Do_Debug = true
local function debugPrint(...)
if Do_Debug then
print("[DEBUG]", ...)
end
end
local function updFeed(txt)
FeedText.Text = txt
FeedText.TextTransparency = 0
task.wait(3)
TweenService:Create(FeedText, TweenInfo.new(1), {TextTransparency = 1}):Play()
end
local function setupConnections()
debugPrint("setting up connections")
local Events = ReplicatedStorage:WaitForChild("Events")
local Functions = Events:WaitForChild("Functions")
local Remotes = Events:WaitForChild("Remotes")
local valTicket = "01_Validation"
local glovesTable = {}
local success, err = pcall(function()
glovesTable = Functions.GetAvailableGloves:InvokeServer(valTicket) or {} -- ensuring glovesTable is always a table
end)
if not success or type(glovesTable) ~= "table" then
glovesTable = {}
InventoryFrame["Denied"]:Play()
local msg = "Error: error to get gloves: " .. tostring(err)
updFeed(msg)
debugPrint(msg)
warn(msg)
end
if #glovesTable == 0 then
updFeed("No gloves available.")
debugPrint("no gloves were found from the server.")
return
end
debugPrint("total gloves received:", #glovesTable)
for _, glove in ipairs(glovesTable) do
if not (glove and glove:IsA("Tool")) then continue end
debugPrint("frame for glove:", glove.Name)
local cloneFrame = script.Template:Clone()
cloneFrame.Name = glove.Name
cloneFrame.Parent = ScrollingFrame
local GloveName = cloneFrame.GloveName
GloveName.Text = glove.Name or "Unknown"
local ReqType = cloneFrame.ReqType
ReqType.Text = glove:GetAttribute("ReqType") or "N/A Type"
local View = cloneFrame.Outline.Viewport
utilMod:UpdateResults(View, glove, false)
cloneFrame.SelectBtn.MouseButton1Click:Connect(function()
utilMod:UpdateResults(SelViewport, glove, true)
SelectFrame.Visible = true
ShownName.Text = glove.Name
ConfirmBtn.MouseButton1Click:Connect(function()
SelectFrame.Visible = false
local changeGloveEvent = Remotes["ChangeGloveEvent"]
local equipSuccess, equipErr = pcall(function()
return changeGloveEvent:FireServer(LocalPlayer, glove.Name, valTicket)
end)
if not equipSuccess then
InventoryFrame["Denied"]:Play()
updFeed("Error equipping glove: " .. tostring(equipErr))
warn("Error equipping glove: " .. tostring(equipErr))
else
InventoryFrame["Equipped"]:Play()
updFeed("Glove Equipped successfully!")
end
end)
end)
end
SearchBox:GetPropertyChangedSignal("Text"):Connect(function()
if SearchBox.Text == "" then
utilMod.ShowAll(ScrollingFrame)
else
utilMod.UpdateResults(SearchBox.Text, ScrollingFrame)
end
end)
end
task.spawn(function()
setupConnections()
SelViewport:ClearAllChildren()
for _, frame in pairs(ScrollingFrame:GetChildren()) do
if frame:IsA("Frame") then
frame:Destroy()
end
end
SearchBox.Text = ""
ShownName.Text = ""
SelectFrame.Visible = false
end)
InventoryFrame:GetPropertyChangedSignal("Visible"):Connect(function()
if InventoryFrame.Visible == true then
setupConnections()
SelViewport:ClearAllChildren()
for _, frame in pairs(ScrollingFrame:GetChildren()) do
if frame:IsA("Frame") then
frame:Destroy()
end
end
SearchBox.Text = ""
ShownName.Text = ""
SelectFrame.Visible = false
end
end)