Help with data store for a plugin

Hello comunity,

i am trying to make a plugin where you can upload song id’s wich other players will see when they open the plugin as well. for this i wanted to use data store and upload the players input to the data store using:

datastore:SetAsync()

when i test it, it all works but if i open the plugin again the data store has been resetted, im asuming this is because in the begin of the script im making a new data store. but i really dont know if its that or what it is and how to fix it please help.

This is my code:

local DataStoreService = game:GetService("DataStoreService")

local songs = DataStoreService:GetGlobalDataStore("Storage", "songs")

    local function UploadSong(id)
    print(globalsongs)
    if #id > 0 then
    if tonumber(id) then
        uiText.Text = Info.checkingData
        uiText.TextColor3 = Colors.blue

        if globalsongs ~= nil then
            for i,v in ipairs(globalsongs) do
                if v == id then
                    uiText.Text = Info.alreadyThere
                    uiText.TextColor3 = Colors.red
                    return false
                end
                end
                table.insert(globalsongs, #globalsongs+1, id)
            else
                globalsongs = {}
                table.insert(globalsongs, 1, id)
            end
            local try, catch = pcall(function()
                songs:SetAsync("All")
            end)
            if try then
                uiText.Text = Info.hasBeenUploaded
                uiText.TextColor3 = Colors.green
            else
                uiText.Text = Info.wentWrong
                uiText.TextColor3 = Colors.red
                wait(catch)
            end
            return true
        else
            uiText.Text = Info.onlyNumber
            uiText.TextColor3 = Colors.red
            return false 
        end
    else
        uiText.Text = Info.blankSpace
        uiText.TextColor3 = Colors.red
        return false
    end
  end

DataStores are not meant to work in plugins and command bars. There is an alternative called plugin:GetSetting() and plugin:SetSetting(), but that will only store info on the local user’s computer.

If you want the plugin to store info globally, you’ll need to use an external database to store data and retrieve it on other user’s machines as well. Note, this can mean your plugin will request for “HTTP Permissions” to access that database site, which users can accept or deny.

(And of course, as with datastores, if you spam HTTP requests, then it may error or fail.)

3 Likes

okay thnx for letting me know,

but since i dont know about HTTP requests where can i foind all information i would need for this plugin?