Change the data of an offline person

I am trying to change the data of an offline person but this code doesn’t seem to be working image

How do I get a specific value from the datastore and change the data?

Any help is appreciated!

3 Likes

You’re trying to use :SetAsync() on the data itself instead of GlobalDataStore.
Fixed one should like this:
data2:SetAsync(id, data.Guild.Member.Value + 5)

doesn’t work any other solutions or can you make it clearer? image

Why did you put dataser.Guild.Member.Value? Are you storing stuff inside of the DataStoreService object itself?

2 Likes

I am trying to change the value this is the file that’s saved. Trying to change the value of the Member Value.

image

While a player is not in the game you need their playerId. When using datastores the key for the player should be their player id always to begin with. Personally from experience I don’t think it’s best to use a datastore that converts to folders and vice versa. Try checking this out.

Example:

local DataStoreService = game:GetService("DataStoreService")
function PlayerAdded(player)
    local scope = "player_" .. player.UserId
    local inventoryStore = DataStoreService:GetDataStore("Inventory", scope)

    -- with that inventoryStore you can use :GetAsync() or UpdateAsync()
end

Now how would you change someone’s data while they are not in the game? If you’re only changing their data once, then you can get away with :SetAsync(), but to be honest :UpdateAsync() is better anyway.

function ChangePlayerData(playerId, datastore, newData)
    -- let's automatically assume datastore is an actual datastore passed
    local scope = "player_" .. playerId
    local success, err = pcall(function()
		datastore:UpdateAsync(scope, function(oldValue)
			local newValue = oldValue or {}
			newValue = newData
			return newValue
		end)
	end)
end

Using it would be like this

local newPlayerInventory = { "sword", "egg", "gun", "wallet" }
ChangePlayerData(1023923, inventoryStore, newPlayerInventory)

I am trying to figure out how to get a certain value out of the datastore
image
I want to know how to fetch a specific value inside of it instead of the actual whole data itself image

I tried using datasave:SetAsync(userID, userID.Storage.PlrInfo.Level.Value + 5) but it doesnt seem to be working

It looks like you’re trying to save an Instance (Storage folder) to a DataStore which you can’t do. Data structures have to look like this

local data = {
    Codes = {},
    PlrInfo = { Exp = 0, Image = "rbxassetid://0", Leader = "userId", Level = 0, Point = 0 },
    Stats = {}
}

Then you can do,

-- after get async()
plrData.PlrInfo.Exp += 1

I recommend checking AlvinBlox’s YouTube video I linked, and recreate that to fit that video format. You can’t save any object / instance to a datastore it has to be either a string, number, bool, or table

Actually I didn’t save the folder when the player joins it clones the folder and then give back the values to each of the folders, say for example; player leaves the game and the script goes into every folder saves the values and then deletes the folder afterwards, when the player joins back it clone the folder in the script make the parent the player than it starts to give back the data to each individual folder.