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

Is this right?

Asked by 10 years ago

I'm trying to get it so that it saves the item's name and the item's number in a value (The item is a GUI button, and the value is inside the button called NumberValue)

-- Save

local Players = game:GetService("Players")

Players.PlayerAdded:connect(function(Plr)
    Plr.Backpack.ChildAdded:connect(function(Item)
        if Plr.DataReady then
            for _, v in pairs(Plr.PlayerGui.Inventory.Frame.Items:GetChildren()) do
                if v ~= nil then
                    Plr:SaveString(v.Name,v.Name)
                    Plr:SaveNumber(v.Name,v.NumberValue.Value)
                end
            end
        end
    end)
end)

Players.PlayerRemoving:connect(function(Plr)
    if Plr.DataReady then
        for _, v in pairs(Plr.PlayerGui.Inventory.Frame.Items:GetChildren()) do
            if v ~= nil then
                Plr:SaveString(v.Name,v.Name)
                Plr:SaveNumber(v.Name,v.NumberValue.Value)
            end
        end
    end
end)

-- Load

game:GetService("Players").PlayerAdded:connect(function(Plr)
    Plr.CharacterAdded:connect(function(Char)
        Plr:WaitForDataReady()

        local last = {}
        local lastposition = UDim2.new(0, 0, 0, 0)
        for _, v in pairs(game:GetService("ReplicatedStorage").Buttons:GetChildren()) do
            if Plr:LoadString(v.Name) == v.Name then
                if (last) then
                print(Plr:LoadString(v.Name))
                cl = v:Clone()
                cl.Parent = Plr.PlayerGui.Inventory.Frame.Items
                cl.Position = UDim2.new(0, 14, 0, 0) + lastposition
                Plr.PlayerGui.Inventory.NumberOfItems.Value = Plr.PlayerGui.Inventory.NumberOfItems.Value +1
                cl.NumberValue.Value = Plr:LoadNumber(v.Value)
                cl.Number.Text = cl.NumberValue.Value.."x"
                end
            last = cl
            lastposition = last.Position + UDim2.new(0, -14, 0, 48)
            end
        end
    end)
end)

1 answer

Log in to vote
0
Answered by 10 years ago

You need to share a more detailed issue, just asking if it's right doesn't help us, we need output codes from the game.

0
Oh, right. Well generally the problem is loading the number value to the button. It usually says "Value is not a valid member of TextButton" which is on line 15 of the load. geckohero17 55 — 10y
Ad

Answer this question