I have an issue, if I try to do table[1], it won’t return that value, and this is critical for the game I’m making. I’ve tried everything I know, but I don’t know why it won’t work. Here’s my defaultdata stuff, basically what _G.sessionData is
My server code: (keep in mind, this is for a custom inventory system im making)
elseif a == "equipSlot" then
print("fired")
-- b = slotNumber
local c = plr.Character
local t = c.ToolHold
print("checking for sesData")
print("SLOT WANTED: "..b)
if not _G.sessionData[plr.UserId] then return end
local tool
tool = rep.resources.tools[_G.sessionData[plr.UserId].
toolbar
[b]
.name]
if not tool then return end
print("TOOL NAME: ".. _G.sessionData[plr.UserId].toolbar[b].name)
if not tool then return end
local ntool = tool:Clone()
if not ntool then return end
print("tool cloned")
ntool.Parent = c
local man = Instance.new("ManualWeld", c.ToolHold)
man.Part1 = t
man.Part0 = ntool.Reference
if man and ntool then
_G.equippedTool = {ntool.Name,b}
end
elseif a == "dequipSlot" then
for _,v in pairs(plr.Character:GetChildren()) do
if v:IsA("Model") and itemData[v.Name] and itemData[v.Name].category == "tools" then
v:Destroy()
_G.sessionData[plr.UserId].equippedTool = {nil,nil}
end
end```
And finally, my client code:
```local num = input.KeyCode.Value - 48
if num >= 1 and num <= 6 then
--// Check if the slot hit is equipped or not
local data = mainF:InvokeServer("requestData")
if data.equippedTool[2] ~= nil or data.equippedTool[2] ~= 0 then
if data.equippedTool[2] == num then
-- dequip slot
functionBank.deselectToolbar()
mainF:InvokeServer("dequipSlot",num)
elseif not data.equippedTool[2] == nil or data.equippedTool[2] == 0 then
--equip slot
functionBank.highlightSlot(num)
mainF:InvokeServer("equipSlot",num)
else
-- dequip equipped tool and equip slot
functionBank.deselectToolbar()
mainF:InvokeServer("dequipSlot",data.equippedTool[2])
mainF:InvokeServer("equipSlot",num)
functionBank.highlightSlot(num)
end
else
functionBank.deselectToolbar()
mainF:InvokeServer("dequipSlot",data.equippedTool[2])
end
end
if num >= 1 and num <= 6 then
--// Check if the slot hit is equipped or not
local data = mainF:InvokeServer("requestData")
if data.equippedTool[2] ~= nil or data.equippedTool[2] ~= 0 then
if data.equippedTool[2] == num then
-- dequip slot
functionBank.deselectToolbar()
mainF:InvokeServer("dequipSlot",num)
elseif not data.equippedTool[2] == nil or data.equippedTool[2] == 0 then
--equip slot
functionBank.highlightSlot(num)
mainF:InvokeServer("equipSlot",num)
else
-- dequip equipped tool and equip slot
functionBank.deselectToolbar()
mainF:InvokeServer("dequipSlot",data.equippedTool[2])
mainF:InvokeServer("equipSlot",num)
functionBank.highlightSlot(num)
end
else
functionBank.deselectToolbar()
mainF:InvokeServer("dequipSlot",data.equippedTool[2])
end
end
[number] only applies to arrays. You’ve made a dictionary table, meaning the value in the square brackets has to be the string name of the value in the table.
I’m trying to access .toolbar, actually.
[b] is a number, and is not nil, but it just wont work, I dont know how to well explain this, but table[number] wont work, the server code is what I sent that is erroring
When taking what you provided and printing the name of the rock it worked correctly. What exactly is it outputting and what is the specific code that is the problem?
if data.equippedTool[2] ~= nil or data.equippedTool[2] ~= 0 then
this always evaluates to true. you probably meant to write and
The formatting in your post is messed up and I can’t tell what table you’re talking about from your original post because you didn’t say. I don’t know what b is, but if it’s a string and not a number then it won’t get anything from the toolbar table that has only numerical indices.
I tried that, thank you, and now I have once again ANOTHER error.
[20:04:03.679 - ServerScriptService.mainServer: bad argument #2 to ‘?’ (string expected, got nil)]
elseif a == "equipSlot" then
print("fired")
-- b = slotNumber
local c = plr.Character
local t = c.ToolHold
print("checking for sesData")
print("SLOT WANTED: "..b)
if not _G.sessionData[plr.UserId] then return end
local tool
tool = rep.resources.tools[_G.sessionData[plr.UserId]
["toolbar"]
[tostring(b)]
.name]
if not tool then return end
print("TOOL NAME: ".. _G.sessionData[plr.UserId]["toolbar"][tostring(b)].name)
if not tool then return end
local ntool = tool:Clone()
if not ntool then return end
print("tool cloned")
ntool.Parent = c
local man = Instance.new("ManualWeld", c.ToolHold)
man.Part1 = t
man.Part0 = ntool.Reference
if man and ntool then
_G.equippedTool = {ntool.Name,b}
end
elseif a == "dequipSlot" then
for _,v in pairs(plr.Character:GetChildren()) do
if v:IsA("Model") and itemData[v.Name] and itemData[v.Name].category == "tools" then
v:Destroy()
_G.sessionData[plr.UserId].equippedTool = {nil,nil}
end
end
Defaultdata has the same code as before, i’m really confused now.
It would help if you were specific at all about the line that errors. It doesn’t look like the code you posted even contains the line that the error occurs on.
line “12” of that code is [tostring(b)], which is a fragment of five lines that should be one line. That error isn’t caused from this. can you click on the error in the output and scroll down to the place where it says the error is, and also specify what actual function is erroring