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

Value gets reverted after changing it what can I do?

Asked by 5 years ago
Edited 5 years ago
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("ETSING BOY")
local ValuesToCreate = {TermsOfUse = {Name = "TermsOfUse", className = "BoolValue", Value = false}}

game.Players.PlayerAdded:Connect(function(Player)
    local Folder = Instance.new("Folder", Player)
    Folder.Name = "PlayerData"

    for i,v in pairs(ValuesToCreate)do
        local Val = Instance.new(v.className, Folder)
        Val.Name = v.Name
    end

    local SavedData
    local success, errormsg = pcall(function()
        SavedData = DS:GetAsync(Player.UserId)
    end)
    if success and SavedData ~= nil then
        print("SAVED DATA OF PLAYER "..Player.Name..": "..game:GetService("HttpService"):JSONEncode(SavedData))
        for i,v in pairs(SavedData)do
            local FindVal = Folder:FindFirstChild(v.Name)
            if FindVal and FindVal.className == v.className then
                FindVal.Value = v.Value
            end
        end
    elseif success and SavedData == nil then
        for i,v in pairs(ValuesToCreate)do
            local FindVal = Folder:FindFirstChild(v.Name)
            if FindVal and FindVal.className == v.className then
                FindVal.Value = v.Value
            end
        end
    elseif not success then
        warn("Error while trying to get saved data of player "..Player.Name..": "..errormsg)
    end
end)

game.Players.PlayerRemoving:Connect(function(Player)
    if not game:GetService("RunService"):IsStudio() then
        local Folder = Player:WaitForChild("PlayerData")
        local SaveData = {}
        for i,v in pairs(Folder:GetChildren())do
            SaveData[v.Name] = {Name = v.Name, className = v.className, Value = v.Value}
        end
        print("SAVING DATA OF PLAYER "..Player.Name..": "..game:GetService("HttpService"):JSONEncode(SaveData))
        local success, errormsg = pcall(function()
            DS:SetAsync(Player.UserId, SaveData)
        end)
        if not success then
            warn("Couldn't save data of player "..Player.Name..": "..errormsg)
        end
    end
end)

game:BindToClose(function()
    for i, Player in pairs(game.Players:GetPlayers())do
        local Folder = Player:WaitForChild("PlayerData")
        local SaveData = {}
        for i,v in pairs(Folder:GetChildren())do
            SaveData[v.Name] = {Name = v.Name, className = v.className, Value = v.Value}
        end
        print("SAVING DATA OF PLAYER "..Player.Name..": "..game:GetService("HttpService"):JSONEncode(SaveData))
        local success, errormsg = pcall(function()
            DS:SetAsync(Player.UserId, SaveData)
        end)
        if not success then
            warn("Couldn't save data of player "..Player.Name..": "..errormsg)
        end
    end
end)

So everytime I change "TermsOfUse" to true I make the datastore script print out the whole table it's going to save and there it says that "TermsOfUse" is false and the datastore saves it as false aswell.

what can I do about it??

0
wait where is the problem? TheluaBanana 946 — 5y
0
The output gives no error but I have a bool value which I want to save by a datastore system and everytime I change the bool value to true the datastore saves it as false Soulmasterluke 7 — 5y
0
so; in other words, u mean that when u set it to true, it reverts to false immediately after? TheluaBanana 946 — 5y
0
so u save it as false right? not that it loads as a false? TheluaBanana 946 — 5y
View all comments (13 more)
0
i can only think of something tht keeps resetting it as false TheluaBanana 946 — 5y
0
or that the script failed to set it to true? TheluaBanana 946 — 5y
0
yes it saves it as false and it loads it as false aswell because it was saved as false although i changed it to true Soulmasterluke 7 — 5y
0
and i change the value by myself using the properties tab or using the console in studio Soulmasterluke 7 — 5y
0
ok TheluaBanana 946 — 5y
0
then either ur hand is broken, or ur script to save it is TheluaBanana 946 — 5y
0
no offense TheluaBanana 946 — 5y
0
xd alright thanks for your help Soulmasterluke 7 — 5y
0
OH CRAP TheluaBanana 946 — 5y
0
i remember TheluaBanana 946 — 5y
0
wait lemme type it out as answer TheluaBanana 946 — 5y
0
i need rep ;-; TheluaBanana 946 — 5y
0
how to rep im new Soulmasterluke 7 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

the datastore does not save anything u change in the studio; only in the game itself. So to really test out wether ur datastore saves, u have to test it in ur actual game

0
good game TheluaBanana 946 — 5y
0
ok thanks im gonna try it out right away Soulmasterluke 7 — 5y
0
lol TheluaBanana 946 — 5y
Ad

Answer this question