Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Saving values in a folder with a datastore?

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?

9 comments

0

Note: On line 13 you keep replacing the value of the datastore when you go through the loop.

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

0

Okay, I'm writing a response.

0

No, wait I'm wrong. I was interpreting it wrong. Sorry.

0

Are you still going to answer and help me?

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?

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

0

Okay. I'm writing it.

0

Okay.

1 answer

✓ Accepted answer

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.

17 comments

0

Alright I'll try it.

0

Wait, I need to edit it.

0

Okay, I fixed it.

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

0

Let me edit it.

0

Try the new script.

0

Doesnt work, no error.

0

could it be something with the code that kicks the player if their value is in the folder

0

Hmm. Does it add the values to the folder?

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.

0

Before the setasync on line 28 can you do print(update) and tell me what it prints?

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

0

It printed my id,the reason

0

Change on line 13 game.ReplicatedStore to game.ReplicatedStorage then tells me if it creates the value in the folder.

0

It didn't put the values. If you wanted to, we could talk on discord to make this easier.

0

Alright. What's your Discord?

0

Familiar#9394

This discussion is preserved as it was. New answers, comments, and votes are closed.