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

How do i save a bool only if it's true to DataStore? [solved]

Asked by
Nogalo 148
7 years ago
Edited by OldPalHappy 7 years ago

This question has been solved by the original poster.

So i made bools named Trophy1...10 for each of the trophies on the map.They work so that once you click a trophy it sets the bool inside your player to true so that you can't click it again as in you've alrdy found this trophy. The trouble is saving this info to Data store.

As you can see i've tried preforming a check to see if the value is true and then if it is it should be saved upon player leaving but that's not the case.

Thanks for your time

local data = game:GetService("DataStoreService")
local dataStor = data:GetDataStore("MobbyProgress")


key = 'MobbyProgress_'..p.userId

    local saveData = dataStor:GetAsync(key)

    if saveData then    
        stage.Value = saveData[1]
        Trophies.Value = saveData[2]
        if Trophy1.Value == true then 
            Trophy1.Value = saveData[3]
             end
    else 
        dataStor:SetAsync(key, {1,0}) 

    end
end)

game.Players.PlayerRemoving:connect(function(p) 
    key = 'MobbyProgress_'..p.userId

    local save = {p.leaderstats.Stage.Value, p.leaderstats.Trophies.Value,p.Trophy1.Value} 

    dataStor:SetAsync(key, save)
end)
0
I am kinda lost, you do not have any checks in the PlayerRemoving event, you simply save the data? User#5423 17 — 7y
0
please ignore my question i've figured it out, turns out i don't even need to check if bools are true or not they get saved regardless, But thank you for taking an interest in solving my problem Nogalo 148 — 7y
0
Can you edit the title with [closed] or something so ppl know User#5423 17 — 7y
0
Put [Solved] in the end of your title. RubenKan 3615 — 7y
0
sorry about that i didn't know but i'll make sure to do that in the future Nogalo 148 — 7y

Answer this question