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

Saving values in a folder with a datastore?

Asked by
H34E7R 19
5 years ago
local rs = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("AdminDatastore")

game:IsLoaded(function()
    DataStore:GetAsync()
end)

game:BindToClose(function()

    wait(10)
    for i,v in pairs(game.ReplicatedStorage.AdminEvents.Banned:GetChildren()) do
        DataStore:SetAsync(v.Name,v.Value)
    end

end)

So I'm experimenting with saving string values names and values when the server shuts down. I need it to set them on the game:IsLoaded part, I'm not sure what to add. Could someone help me if theres anything I need to add on the bindtoclose part, and what to add on the isloaded part to get it to work correct?

0
Note: On line 13 you keep replacing the value of the datastore when you go through the loop. TypicallyPacific 61 — 5y
0
Then how would I fix that? I also need to set the values into the folder as well which is what i'm needing help with H34E7R 19 — 5y
0
Okay, I'm writing a response. TypicallyPacific 61 — 5y
0
No, wait I'm wrong. I was interpreting it wrong. Sorry. TypicallyPacific 61 — 5y
View all comments (5 more)
0
Are you still going to answer and help me? H34E7R 19 — 5y
0
Do you want to make it so if they join and they're on the list they get kicked for the reason of v.Value? TypicallyPacific 61 — 5y
0
I already have that. I need it so the values save when the game is shutdown and then they're put back in when the game is launched H34E7R 19 — 5y
0
Okay. I'm writing it. TypicallyPacific 61 — 5y
0
Okay. H34E7R 19 — 5y

1 answer

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

Alright. So when you do the loop each time it saves the value to a key. If you want it to get every single banned person you're going to have to save it in one value and split it once the game is loaded.

local rs = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("AdminDatastore")

repeat wait() until game.ReplicatedStorage.AdminEvents.Banned
    local one = DataStore:GetAsync("bans")
    local two = string.split(one, "|")
    for i,v in pairs(two) do
        local three = Instance.new("StringValue")
        local four = string.split(v, ",")
        three.Name = four[1]
        three.Value = four[2]
        three.Parent = game.ReplicatedStorage.AdminEvents.Banned
    end

game:BindToClose(function()
    local update
    for i,v in pairs(game.ReplicatedStorage.AdminEvents.Banned:GetChildren()) do
        if update == nil then
            update = v.Name..","..v.Value
        else
            update = update.."|"..v.Name..","..v.Value
    end
    end
    DataStore:SetAsync("bans",update)

end)

Tested! It works now.

0
Alright I'll try it. H34E7R 19 — 5y
0
Wait, I need to edit it. TypicallyPacific 61 — 5y
0
Okay, I fixed it. TypicallyPacific 61 — 5y
0
At the if i =1 then in the game:BindToClose it says expected then, got =. If I make it == then it says it doesn't know what the bans is H34E7R 19 — 5y
View all comments (13 more)
0
Let me edit it. TypicallyPacific 61 — 5y
0
Try the new script. TypicallyPacific 61 — 5y
0
Doesnt work, no error. H34E7R 19 — 5y
0
could it be something with the code that kicks the player if their value is in the folder H34E7R 19 — 5y
0
Hmm. Does it add the values to the folder? TypicallyPacific 61 — 5y
0
No it doesn't add values to the folder. I put my ID in there and it didn't add the string value to the folder. H34E7R 19 — 5y
0
Before the setasync on line 28 can you do print(update) and tell me what it prints? TypicallyPacific 61 — 5y
0
Do you want to see the code that kicks the player if their id is the name of the string value and the reason is the value of the string value H34E7R 19 — 5y
0
It printed my id,the reason H34E7R 19 — 5y
0
Change on line 13 game.ReplicatedStore to game.ReplicatedStorage then tells me if it creates the value in the folder. TypicallyPacific 61 — 5y
0
It didn't put the values. If you wanted to, we could talk on discord to make this easier. H34E7R 19 — 5y
0
Alright. What's your Discord? TypicallyPacific 61 — 5y
0
Familiar#9394 H34E7R 19 — 5y
Ad

Answer this question