Datastore Help/Question

In my admin panel, I’m working on right now I have a ban feature:

		["IsBanned"] = true,
		["Reason"] = reason,
		["Offenses"] = 1
	})

But I want to make it when the player is either kicked or banned their “Offenses” go up by 1 but I’m not sure how to add Stuff inside a datastore any ideas? I’ll do the rest such as detecting the number of offenses and if it’s like 5 or something they get banned. Much appreciated if you do help!

1 Like

Do you not cache a player’s data in the current session with a table anywhere? Are you directly writing to a player’s data in a DataStore and that’s where you need help? UpdateAsync allows you the opportunity to transform data so that should be what you’re using if you don’t have an in-session cache.

Store:UpdateAsync(player_key, function(savedData, keyInfo)
    local userIds = keyInfo:GetUserIds()
    local metadata = keyInfo:GetMetadata()

    savedData.Offenses += 1

    return savedData, userIds, metadata
end)
2 Likes

No, I don’t when I first made this I guess I had no reason to, should I be doing this and how would I store data in a table if the player isn’t in the game (You can use UserIds to ban people).

I figured it out myself (without using tables lol)

1 Like

If the player isn’t present in the game you shouldn’t need to modify their data unless you need to retroactively change their data manually.

What you can do is call “:GetAsync()” with their key. With the retrieved data you can then modify it as you desire and then call :“SetAsync()” with the same key in order to override their existing data with the modified version. This can also be achieved with “:UpdateAsync()” as has been suggested.