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

How to convert a Player Data Store into a Global One? Or make all players use the same DataStore?

Asked by 5 years ago

I have the following script which saves Banned People that a moderator banned into a DataStore. The problem is, when another moderator tries to load in the DataStore the player doesn't have access to the other player's DataStore. Is there any way to make all moderators change the EXACT SAME DataStore and load the ExactSame data store to each one?

Here's the script i have which is not that long:

Note: If I have to completely rewrite it, it's fine as long as It works! I appreciate whoever helps me fix this issue and will give a thumbs up and a Accept.

local DSS = game:GetService("DataStoreService")


local BannedPeopleStore = DSS:GetGlobalDataStore("BannedPeopleStoreORIGINAL")
local BannedPeopleStore2 = DSS:GetGlobalDataStore("BannedPeopleStore2ORIGINAL")

function generateBannedDataKey(player)
    local ret = "uids_StoreKey1" 
--I changed to be the same to all players instead of uids_..player.UserId and did not work
    return ret
end

function GenerateBannedTable2(player)
    local dataTable = {}
    return dataTable
end

function generateBannedTable(player)
local dataTable = {}
local BannedPlayers = script:WaitForChild("BannedPlayers"):GetChildren()
for i =1 , #BannedPlayers do
    table.insert(dataTable,tostring(BannedPlayers[i]))
    print(tostring(BannedPlayers[i]).." checked!")
end


    return dataTable
end

function saveBannedPlayersForPlayer(player)
    local key = generateBannedDataKey(player)
    local dataP = generateBannedTable(player)
    BannedPeopleStore:SetAsync(key, dataP)
    print("Saved!")
end

function inputBannedPeopleForPlayer(player, dataP)
local BannedPlayers = script:WaitForChild("BannedPlayers"):GetChildren()
    for i,v in pairs(dataP) do
        local PlayerToAdd = Instance.new("StringValue",script:WaitForChild("BannedPlayers"))
        PlayerToAdd.Name = tostring(v)
        PlayerToAdd.Value = tostring(v)
    end
end

function loadBannedPeopleForPlayer(player)

    local key = generateBannedDataKey(player)
    local dataP = BannedPeopleStore:GetAsync(key)
    if dataP then
    inputBannedPeopleForPlayer(player, dataP)
    else
    local key = generateBannedDataKey(player)
    local dataP2 = GenerateBannedTable2(player)
    BannedPeopleStore2:SetAsync(key, dataP2)

    end
end


--------------/////Save and Load data\\\\\-----------------

script:WaitForChild("Save").onServerEvent:connect(function(PlayerWhoSentSaveRequest)
   saveBannedPlayersForPlayer(PlayerWhoSentSaveRequest)
   saveSettingsForPlayer(PlayerWhoSentSaveRequest)
   print("Saving..")
end)

script:WaitForChild("Load").onServerEvent:connect(function(PlayerWhoSentLoadRequest)
   loadBannedPeopleForPlayer(PlayerWhoSentLoadRequest)
   loadSettingsForPlayer(PlayerWhoSentLoadRequest)
   print("Loading..")
end)

I would really really appreciate if anyone could help me with this issue.. I tried chaging the key to be the same key to everyone and changing GetDataStore to GetGlobalDataStore but nothing worked.

If I have to rewrite a completely new script I will, as long as it works. I thanks to whoever helps me with this issue.

Help please.

Answer this question