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

How would i change values using Datastores?

Asked by 7 years ago

ive used GetAsync() as in a variable then looped my table "ValsToset" with the datastore table "saves" to set the values but everytime i try to get the values they wouldnt be able to set

local event1 = Instance.new("RemoteEvent",game.ReplicatedStorage)--outfit1
event1.Name = "outfit1"
local event2 = Instance.new("RemoteEvent",game.ReplicatedStorage)
event2.Name = "outfit2"
local event3 = Instance.new("RemoteEvent",game.ReplicatedStorage)
event3.Name = "outfit3"


event1.OnServerEvent:connect(function(player,plr,data)
    print 'fired'
    local outfit1 = game:GetService("DataStoreService"):GetDataStore("Outfit1")
    local key = "player-"..plr.userId
    local plrstats = plr.Customization--Order in stats are saved {Hairs,Face,Shirt,Pants,Accessories1-5"}

    local valsToset = {
        plrstats.Hair.Value,
        plrstats.Hair2.Value,
        plrstats.Face.Value,
        plrstats.Shirt.Value,
        plrstats.Pants.Value,
        plrstats.Accessory1.Value,
        plrstats.Accessory2.Value,
        plrstats.Accessory3.Value,
        plrstats.Accessory4.Value,
        plrstats.Accessory5.Value,
    }


    local saves = outfit1:GetAsync(key)

    if data == "save" then
        print 'saving'
        outfit1:SetAsync(key,valsToset)
        print 'saved'
    for i,v in pairs(valsToset) do      
        print(v)
    end

    elseif data == "load" then--looping the tables values with saved to load them in
        print 'loading'
    for i,v in pairs(valsToset) do      
            valsToset[i] = saves[i]
            print(valsToset[i])
    end
    elseif data == "check" then
        print 'checking'
    for i,v in pairs(saves) do      
            print(saves[i])
    end



    end
end)

0
What do you mean? Setting the values doesn't work? GoldenPhysics 474 — 7y

1 answer

Log in to vote
1
Answered by
einsteinK 145
7 years ago
Edited 7 years ago

In the save, you probably want to set the Value of all the IntValues:

local event1 = Instance.new("RemoteEvent",game.ReplicatedStorage)--outfit1
event1.Name = "outfit1"
local event2 = Instance.new("RemoteEvent",game.ReplicatedStorage)
event2.Name = "outfit2"
local event3 = Instance.new("RemoteEvent",game.ReplicatedStorage)
event3.Name = "outfit3"


event1.OnServerEvent:connect(function(player,plr,data)
    print 'fired'
    local outfit1 = game:GetService("DataStoreService"):GetDataStore("Outfit1")
    local key = "player-"..plr.userId
    local plrstats = plr.Customization--Order in stats are saved {Hairs,Face,Shirt,Pants,Accessories1-5"}

    local vals = {
        plrstats.Hair,
        plrstats.Hair2,
        plrstats.Face,
        plrstats.Shirt,
        plrstats.Pants,
        plrstats.Accessory1,
        plrstats.Accessory2,
        plrstats.Accessory3,
        plrstats.Accessory4,
        plrstats.Accessory5,
    }

    local valsToset = {}
    for k,v in pairs(vals) do
        valsToSet[k] = v.Value
    end

    local saves = outfit1:GetAsync(key)

    if data == "save" then
        print 'saving'
        outfit1:SetAsync(key,valsToset)
        print 'saved'
    for i,v in pairs(valsToset) do      
        print(v)
    end

    elseif data == "load" then--looping the tables values with saved to load them in
        print 'loading'
    for i,v in pairs(vals) do      
            vals[i].Value = saves[i]
            print(saves[i])
    end
    elseif data == "check" then
        print 'checking'
    for i,v in pairs(saves) do      
            print(saves[i])
    end
    end
end)


0
bro thanks a ton for that xlaser23 60 — 7y
Ad

Answer this question