Data Stores getting lost in translation?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make logs for my game using data storage.

  2. What is the issue? Include screenshots / videos if possible!
    The data storage thing is doing random numbers.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried printing them and it was perfectly fine, and I don’t think there is any solution for this.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here is my code

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("Ban")

local startinglogs = {ds:ListKeysAsync()}
script.Parent.LogsString.Value = ds:GetAsync(startinglogs)

script.Parent.Parent.Parent.Parent.BanGUI.Ban.OnServerEvent:Connect(function(plr,plrtoban,reason,days,status) -- When you fire the server
	local uid = game.Players:GetUserIdFromNameAsync(plrtoban) -- If they aren't in the server, it gets the id anyway with no error unless it's an invalid name
	if game.Players:FindFirstChild(plrtoban) == nil or uid == 381203209 then
		local logs = {ds:ListKeysAsync().Cursor .. ", ".. plr.Name.. " tried banning ".. plrtoban .. " for ".. reason}
		print(logs)
		print(ds:ListKeysAsync())
		print(plr.Name.. " tried banning ".. plrtoban .. " for ".. reason)
		script.Parent.LogsString.Value = ds:SetAsync(logs, script.Parent.LogsString.Value)
		print(script.Parent.LogsString.Value)
	else
		game.Players:FindFirstChild(plrtoban):Kick("You have been banned\n For: "..reason.."by:".. plr.Name)
		local logs = {ds:ListKeysAsync(), plr.Name.. " banned ".. plrtoban .. " for ".. reason}-- Kick if they are in the server
		print(logs)
		print(ds:ListKeysAsync())
		print(plr.Name.. " banned ".. plrtoban .. " for ".. reason)
		script.Parent.LogsString.Value = ds:SetAsync(logs, script.Parent.LogsString.Value)
	end
end)

while wait() do
	script.Parent.TextLabel.Text = script.Parent.LogsString.Value
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Can you please explain what you believe the SetAsync code is doing / what you want it to do? Looking at it, you are trying to use a table as the key, which wouldn’t really make sense.

Can you come up with a better way?

it seems you want to store a list of who banned whom for reason

function AddBanLog(plr: Player, plrtoban: string, reason: string, days: number, status: string)
	local uid = game.Players:GetUserIdFromNameAsync(plrtoban)
	local key = `Player/{plr.UserId}/{os.time()}` -- it should be more relevant to be the key. we assume the player will at most ban one person each second
	local log
	if game.Players:FindFirstChild(plrtoban) == nil or uid == 381203209 then
		log = `{plr.Name} tried banning {plrtoban} for {reason}`
	else
		log = `{plr.Name} banned {plrtoban} for {reason}`
	end
	while true do
		local success, error = pcall(function() return ds:SetAsync(key, log) end)
		if success then break end
		task.wait(1) -- wait a bit and retry is database error
	end
end

the choice for the key is that, you can then list out whom a particular moderator has banned

function GetBannedBy(plr: Player)
	local pages = ds:ListKeysAsync(`Player/{plr.UserId}`)
	while true do
		local keys = pages:GetCurrentPage()
		for _, key in keys do
			local log = ds:GetAsync(key)
			print(log)
		end
		if pages.IsFinished then break end
		pages:AdvanceToNextPageAsync()
	end
end

see Players:BanAsync ; they also have some sample code for you to look at.

local Players = game:GetService("Players")
local function ban(name, reason, days, status)
	local uid = tonumber(name) or Players:GetUserIdFromNameAsync(plrtoban)
	Players:BanAsync({
		UserIds = {uid},
		Duration = 24*60*60 * days,
		DisplayReason = "You have been banned for "..tostring(days).." days for "..reason,
		PrivateReason = reason
	})
end

unfortunately notice that these are not directly visible from Creator Hub > Moderations > Bans
and we have to know the banned userId to retreive the ban history with Players:GetBanHistoryAsync

so we need to store the plrtoban userId to integrate with these API

I’ve not used this server much but there is a whole section that lists bans right?


So I don’t really get what you mean when you say it’s not visible here.
In the function I wrote it says local uid = tonumber(name) or Players:GetUserIdFromNameAsync(plrtoban) which takes either the userid or the name of the player. Since I haven’t tested or looked into Roblox’s ban system much, I don’t know what a banned user looks like in the creator hub, but I would guess it would display their name and a link to their profile.

Here I did 5 mins of looking:

If you need the ids to ban from the website, open studio and run print(game.Players:GetUserIdFromNameAsync("namehere")) in command line.

I figured it out, I just did something random and fidgeted around with the code and figured it out, thanks for the help!

we used the in experience banning api before and it doesn’t show on this web page.
the web page on shows those that are banned by using the web page only.