I was correct, the tool gets destroyed by the server.
is there a way to fix that in the code?
and why is it only being destroyed when im on mobile or clicking it? not when i use the key input?
Because for the key input, you are referencing another tool, while the gui is referencing the same tool
how should i go about referencing the exact tool in the code?
toolCircle.Image.MouseButton1Click:Connect(function()
tool = KEY_DICTIONARY[ item ]
handleEquip(tool)
end)
now that i implemented that i cant click it at all and im getting this output error
15:48:06.253 Players.DemonicPandazYT.PlayerGui.BackpackUI.BackpackScript:27: attempt to index nil with âParentâ - Client - BackpackScript:27
15:48:06.253 Stack Begin - Studio
15:48:06.253 Script âPlayers.DemonicPandazYT.PlayerGui.BackpackUI.BackpackScriptâ, Line 27 - function handleEquip - Studio - BackpackScript:27
15:48:06.253 Script âPlayers.DemonicPandazYT.PlayerGui.BackpackUI.BackpackScriptâ, Line 155 - Studio - BackpackScript:155
15:48:06.254 Stack End - Studio
It only works if im using my keys now.
i put it in the create tool function
local function create(tool)
local index = 0
for i, v in pairs(items) do
if v.Name == tool.Name then index = i break end
end
local _toolCircle = Frame.Contents:FindFirstChild(`{tool.Name}{index}`)
if _toolCircle then
_toolCircle:SetAttribute("Amount", _toolCircle:GetAttribute("Amount") + 1)
_toolCircle.Stacks.Text = tostring(_toolCircle:GetAttribute("Amount"))
table.insert(stackedItems, tool)
return
end
table.insert(items, tool)
local nextIndex = (#items == 10) and 0 or #items
local isVisible = (maxOnHotbar == 10) and (nextIndex <= 9 and true or false) or ((nextIndex ~= 0 and nextIndex <= maxOnHotbar) and true or false)
local toolCircle = Template:Clone()
toolCircle.LayoutOrder = #items
toolCircle.Name = `{tool.Name}{#items}`
toolCircle.Size = UDim2.new(0, Frame.Contents.AbsoluteSize.Y, 0, Frame.Contents.AbsoluteSize.Y)
toolCircle.Visible = isVisible
toolCircle.Image.Image = tool.TextureId
toolCircle.Index.Text = nextIndex
toolCircle.Stacks.Text = "1"
toolCircle.FixedName.Text = tool.TextureId == "" and tool.Name or ""
toolCircle.Parent = Frame.Contents
toolCircle:SetAttribute("Amount", 1)
toolCircle.Image.MouseButton1Click:Connect(function()
tool = KEY_DICTIONARY[items]
handleEquip(tool)
end)
checkHotbar()
tool.Activated:Connect(function()
updateRemove(tool, toolCircle:GetAttribute("Amount") > 1)
end)
end
local isMouseButtonDown = false
local function create(tool)
local index = 0
for i, v in pairs(items) do
if v.Name == tool.Name then
index = i
break
end
end
local _toolCircle = Frame.Contents:FindFirstChild(tool.Name .. index)
if _toolCircle then
_toolCircle:SetAttribute("Amount", _toolCircle:GetAttribute("Amount") + 1)
_toolCircle.Stacks.Text = tostring(_toolCircle:GetAttribute("Amount"))
table.insert(stackedItems, tool)
return
end
table.insert(items, tool)
local nextIndex = (#items == 10) and 0 or #items
local isVisible = (maxOnHotbar == 10) and (nextIndex <= 9 and true or false) or ((nextIndex ~= 0 and nextIndex <= maxOnHotbar) and true or false)
local toolCircle = Template:Clone()
toolCircle.LayoutOrder = #items
toolCircle.Name = tool.Name .. #items
toolCircle.Size = UDim2.new(0, Frame.Contents.AbsoluteSize.Y, 0, Frame.Contents.AbsoluteSize.Y)
toolCircle.Visible = isVisible
toolCircle.Image.Image = tool.TextureId
toolCircle.Index.Text = nextIndex
toolCircle.Stacks.Text = "1"
toolCircle.FixedName.Text = tool.TextureId == "" and tool.Name or ""
toolCircle.Parent = Frame.Contents
toolCircle:SetAttribute("Amount", 1)
toolCircle.Image.MouseButton1Down:Connect(function()
isMouseButtonDown = true
end)
toolCircle.Image.MouseButton1Up:Connect(function()
if isMouseButtonDown then
handleEquip(tool)
end
isMouseButtonDown = false
end)
tool.Activated:Connect(function()
updateRemove(tool, toolCircle:GetAttribute("Amount") > 1)
end)
end
i edited it to work for clicking and keyboard. But i still get the same error, i think its the handle equip function.
I was thinking something like this:
toolCircle.Image.MouseButton1Click:Connect(function()
local index = string.gmatch(toolCircle.Name,â%d+â)
index = tonumber(index())
tool = items[index]
handleEquip(tool)
end)
thanks so much dude can u explain what u did?
Youâre using the items index for the keycode, so I simply did the same. You assigned the index with the name of the gui at the end of the string, I simply took that number as the index.
ohh i see, thanks so much man!
If I solved this current problem, then you may mark it as the solution.
yup already done thanks for the help.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.