Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

how to make count the number of items in a frame ?

Asked by 10 years ago

output:01:02:56.481 - Players.Player1.PlayerGui.ScreenGui.LocalScript:78: attempt to get length of upvalue 'a' (a userdata value)

local gui = script.Parent
local guii = gui.Frame
local button1 = gui.button
local Button = script.Parent.TextButton
local slots = gui.Frame
local m = script
local pack
local ply = gui.Parent.Parent
local selected
local storage = gui.storage.Value
local s = 0
local a = slots:GetChildren()


button1.MouseButton1Up:connect (function()
    a = Instance.new("TextLabel")
    a.Parent = game.Lighting:findFirstChild(ply.Name.."sPack")

if s == 3 then
    print (s)

end
end)


y = 0.03
x = 0.01
maxX = 0.9
maxY = 0.9
-- Y + 60
-- X + 40
function getMyPack()
pack = game.Lighting:findFirstChild(ply.Name.."sPack")
end

function set(button)
if selected ~= nil then selected=nil selected["Selected"]:Remove() end
wait(.01)
selected=button
p=m.Bevel:Clone()
p.Parent=button
p.Name="Selected"
end

function removeOldOutOfTheWay(location)
for index, child in pairs(location) do
if child.Name == "TextButton" then
child:Remove()
y = 0.03
x = 0.01
end
end
end

function New()
removeOldOutOfTheWay(slots:getChildren())
local lo = pack:getChildren()
for index, child in pairs(lo) do
neww = Button:Clone()
neww.Position = UDim2.new(x, 0, y, 0)
neww.Text = child.Name
neww.Parent = slots
neww.MouseButton1Down:connect(function() set(neww) end)
x = x + 0.2
if x > 0.9 then
y = y +0.25
x = 0.01
end
end
end


getMyPack()
New()

pack.ChildAdded:connect(function()
New()
for i = 1,#a do -------------------------------------------Problem
    a[i] = s+1
end

end)

pack.ChildRemoved:connect(function()
New()
end)

1 answer

Log in to vote
0
Answered by 10 years ago

When MouseButtonUpis fired the variable a is resigned to another value. To fix this we can rename the variable or make it a local variable.

local a = slots:GetChildren()


button1.MouseButton1Up:connect (function()
    local a = Instance.new("TextLabel")
    a.Parent = game.Lighting:findFirstChild(ply.Name.."sPack")

if s == 3 then
    print (s)

end
end)

0
i see i guess i forgot i like to use a a lot :x Layfonex 0 — 10y
0
'a' is almost always a bad variable choice. Variables should be named something that relates to what they equal, for readability and organization purposes. It also helps with debugging, as you won't have to look back at what it equals. It also prevents this problem. Perci1 4988 — 10y
Ad

Answer this question