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

Inventory system not working and very glitchy. Help?

Asked by
Protall 10
9 years ago
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?

0
Is there anything from the output? bobafett3544 198 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Please tell output but anyway...

Does SourceScript return a table??? If not, that's your problem. You can't index functions in ModuleScripts using function() end .

Try changing the instance function in the table; by following this example: YourKeyNameHere.FunctionName = function(name, instance, parent)

Hope this helps! If not tell output. ~marcoantoniosantos3

0
Sorry for the late response but no there is no output and yes SourceScript returns a table. It is a module script in workspace that returns a table with 2 tables in it named instances and commonInstances that each have functions that each return stuff. The modulescript is not the issue. Protall 10 — 9y
Ad

Answer this question