numbers = {}
local add = require(workspace:WaitForChild("SourceScript"))
--[[is a modulescript in workspace. only instance i add is an ImageButton and args are add.instance(name, instance, parent)
]]
local function Update()
for i,v in pairs(numbers) do
table.remove(numbers, i)
end
for i,v in pairs(script.Parent:GetChildren()) do
if v:isA("ImageButton") then
v:remove()
end
end
local Spot = 1
for i,v in pairs(game.Players.LocalPlayer:WaitForChild("Inv"):GetChildren()) do
table.insert(numbers, v)
table.sort(numbers, function(x,y) return x.Spot.Value < y.Spot.Value end)
if numbers[i + 1] then
if v.Spot.Value < (numbers[i + 1].Spot.Value - 1) then
numbers[i + 1].Spot.Value = v.Spot.Value + 1
end
if v.Spot.Value >= 4 and v.Spot.Value < 7 then
v.rowNum.Value = 2
elseif v.Spot.Value >= 7 and v.Spot.Value < 10 then
v.rowNum.Value = 3
elseif v.Spot.Value >= 10 and v.Spot.Value < 13 then
v.rowNum.Value = 4
elseif v.Spot.Value >= 13 and v.Spot.Value < 16 then
v.rowNum.Value = 5
elseif v.Spot.Value >= 16 and v.Spot.Value < 19 then
v.rowNum.Value = 6
end
end
local newButton = add.instance(i, "ImageButton", script.Parent)
newButton.Name = v.Spot.Value
newButton.Size = UDim2.new(.25,0,.1,0)
newButton.Image = game.ReplicatedStorage[v.Name].Texture
script.delScript:Clone().Parent = newButton
newButton.delScript.Disabled = false
Spot = Spot + 1
if v.Spot.Value == 1 or v.Spot.Value == 4 or v.Spot.Value == 7 or v.Spot.Value == 10 or v.Spot.Value == 13 or v.Spot.Value == 16 or v.Spot.Value == 19 then
newButton.Position = UDim2.new(.065 ,0,(.125 + ((v.rowNum.Value-1)*.25)/2),0)
Spot = 1
else
newButton.Position = UDim2.new((.065 + (.3 * (Spot-1))) ,0, (.125 + ((v.rowNum.Value - 1)*.25)/2), 0)
end
end
end
Update()
Update()
script.Parent:WaitForChild("money").Text = "Money: $"..game.Players.LocalPlayer:WaitForChild("stats"):WaitForChild("money").Value
game.Players.LocalPlayer:WaitForChild("Inv").ChildAdded:connect(function(child)
child:WaitForChild("Spot")
Update()
Update()
end)
game.Players.LocalPlayer:WaitForChild("Inv").ChildRemoved:connect(function(child)
Update()
Update()
end)
game.Players.LocalPlayer:WaitForChild("stats"):WaitForChild("money").Changed:connect(function(value)
script.Parent.Money.Text = "Money: $"..value
script.Parent.Parent.CoinSound:Play()
end)
When it updates, the gui glitches out and pretty much doesn't work. What have I done wrong?

1 comment
Is there anything from the output?