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

How would I make this be able to save Color3 values as well?

Asked by
oSyM8V3N 429 Moderation Voter
4 years ago
local DSService = game:GetService('DataStoreService'):GetDataStore('DBSRClosedTestv9')
game.Players.PlayerAdded:connect(function(p)
    wait(game.Lighting.TimeToLoad.Value)
    -- Define variables
    local stats = game.ServerStorage.PlayerData:Clone()
    stats.Parent = p
    stats.Level.Value = 1
    stats.StrengthValue.Value = 0
    stats.speedValue.Value = 1
    stats.maxKi.Value = 100
    stats.MaxStaminaValue.Value = 100
    stats.kiDamage.Value = 0
    stats.kiControl.Value = 0
    stats.kiValue.Value = 100
    stats.AgilityValue.Value = 0
    stats.PowerLevel.Value = 100
    stats.currentHealth.Value = 100
    stats.defenseValue.Value = 0
    stats.attributePoints.Value = 0
    stats.exp.Value = 0
    stats.Zeni.Value = 0
    stats.Hair.Value = 0
    stats.BodyHeight.Value = 1
    stats.BodyWidth.Value = 1
    print("Done")
    --stats.mouth.Value = 1
    stats.Face.Value = 1
    local uniquekey = 'id-'..p.userId
    local names = {}
    for i, v in pairs(p.PlayerData:GetChildren()) do
        table.insert(names, v.Name)
    end

    -- GetAsync
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        for i, v in pairs(p.PlayerData:GetChildren()) do
            v.Value = GetSaved[i]
        end

        for i=1, #GetSaved do
                print(i .. ": " .. names[i] .. " = " .. tostring(GetSaved[i]))
        end
    else
        local NumbersForSaving = {}
            for i, v in pairs(p.PlayerData:GetChildren()) do
                table.insert(NumbersForSaving, v.Value)
            end
        DSService:SetAsync(uniquekey, NumbersForSaving)
    end
end)

game.Players.PlayerRemoving:connect(function(p)
    local uniquekey = 'id-'..p.userId
    local Savetable = {}
        for i, v in pairs(p.PlayerData:GetChildren()) do
            table.insert(Savetable, v.Value)
        end

    DSService:SetAsync(uniquekey, Savetable)            
end)

1 answer

Log in to vote
0
Answered by 4 years ago

You can create a Color3Value and just save the Value

0
it pops up an error when I do so oSyM8V3N 429 — 4y
Ad

Answer this question