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

How to add a Number value to a table alongside StringValue?

Asked by 5 years ago
Edited 5 years ago

Greetings! I'm working on a DataStore of which saves the name of the Value and also the Value itself, the code itself is working fine other than when I add the 'v.Value' within the table.insert -

Output is throwing out: "Bad argument:12 #2 to 'insert' Number Expected, got string.".

Any help would be appreciated.

local SaveID = 'ID:' .. Player.userId

    local save = {}

    for i,v in pairs(Player:WaitForChild("PlayerData"):GetDescendants()) do
    if v:IsA("NumberValue") or v:IsA("StringValue") then
    table.insert(save, {v.Name, v.Value, v.ClassName}) 
    print("Name: " .. v.Name .. " CP: " .. v.Value .. " IsA: " .. v.ClassName)
    else end
    end

    DSService:SetAsync(SaveID, save)
    print("Saved!")

EDIT: First half is working now, however my current issue is returning the values back to the server and 'loading' them.

local SaveID = 'ID:' .. Player.userId
    local GetSaved = DSService:GetAsync(SaveID)
    if GetSaved then
        for i,v in pairs (GetSaved) do
        local Saved = Instance.new("NumberValue", Player:WaitForChild("PlayerData"))
        Saved.Name = GetSaved[2]
        Saved.Value = GetSaved[3]
        end
    else
        print("Save file not found")
    end
0
Instance.new("class",parent) is deprecated. use a variable to create (you already are using) and use YOURVARIABLE.Parent = yourParent yHasteeD 1819 — 5y

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

If you wanted to make a string index, use this:

save[v.Name] = v.Value
0
This method seems much cleaner than working with [1], [2] etc. Though I'm not familiar with String indexes. Any chance of elaborating? KossmoZ 4 — 5y
Ad

Answer this question