Can't save a table in the data store

I want to make a Ban System. I made a datastore called : “BanData”. I also made a table with the end time and the reason. but it show an error while saving the table.

103: Dictionary is not allowed in data stores.

Here the code :

local TimeNow = os.time()
local EndTime = TimeNow + TotalTime

local Day = math.floor(TotalTime / 86400)
TotalTime -= Day * 86400

local Hour = math.floor(TotalTime / 3600)
TotalTime -= Hour * 3600

local Min = math.floor(TotalTime / 60)
TotalTime -= Min * 60

local Length = Day.. "d-" ..Hour.. "h-" ..Min.. "min"

Send(Target, player, Reason, Length)

local BanTable = {}

BanTable = {
	["EndTime"] = EndTime,
	["Reason"] = Reason
}

local success, err = pcall(function()
	BanData:SetAsync(Target.UserId, BanTable)
end)

if success then
	print("Successfuly ban " ..Target.Name.. " for " ..Day.. "d-" ..Hour.. "h-" ..Min.. "min.")
else
	print("Something wrong happened while banning " ..Target.Name.. ".")
	warn(err)
end

I don’t know why it’s not working. Few weeks ago I successfuly saved a table, but here it’s not working… Any help will be appreciated !

You gotta compress the dictionary with HTTPService:JSONEncode() before saving it.

I don’t very understand with HttpService can you send me the script ?

local encodedData = game:GetService("HttpService"):JSONEncode(BanTable)

then save that.

Sorry I said JSONDecode it should have been JSONEncode try that instead.

Now it’s say this error :

103: string is not allowed in data stores.

Do you want I send to the whole script ?

local DataStoreService = game:GetService("DataStoreService")
local ServerScriptService = game:GetService("ServerScriptService")
local Https = game:GetService("HttpService")

local BanData = DataStoreService:GetOrderedDataStore("BanData")

local RemoteEvent = game.ReplicatedStorage.RemoteEvents.BanEvent
local UnbanEvent = game.ReplicatedStorage.RemoteEvents.UnbanEvent
local BanTag = ServerScriptService.AdminPad.BanTag

game.Players.PlayerAdded:Connect(function(player)
	local sucess, PlayerData = pcall(function()
		return BanData:GetAsync(player.UserId)
	end)
	
	if PlayerData then
		local EndTime = PlayerData.EndTime
		local Reason = PlayerData.Reason
		
		local TimeNow = os.time()
		
		if EndTime > TimeNow then
			local Duration = EndTime - TimeNow
			
			local Day = math.floor(Duration / 86400)
			Duration -= Day * 86400

			local Hour = math.floor(Duration / 3600)
			Duration -= Hour * 3600

			local Min = math.floor(Duration / 60)
			Duration -= Min * 60
			
			player:Kick("You are banned. For the next reason : " ..Reason.. " Comeback in: " ..Day.. "d-" ..Hour.. "h-" ..Min.. "min.")
		else
			BanData:RemoveAsync(player.UserId)
		end
	end
end)

RemoteEvent.OnServerEvent:Connect(function(player, Target, TotalTime, Reason)
	if Target then
		local result = BanTag:Invoke(player, Target)
		
		if result then
			local TimeNow = os.time()
			local EndTime = TimeNow + TotalTime

			local Day = math.floor(TotalTime / 86400)
			TotalTime -= Day * 86400

			local Hour = math.floor(TotalTime / 3600)
			TotalTime -= Hour * 3600

			local Min = math.floor(TotalTime / 60)
			TotalTime -= Min * 60

			local Length = Day.. "d-" ..Hour.. "h-" ..Min.. "min"
			
			Send(Target, player, Reason, Length)
			
			local BanTable = {
				["EndTime"] = EndTime,
				["Reason"] = Reason
			}
			
			local encodedData = Https:JSONEncode(BanTable)
			
			local success, err = pcall(function()
				BanData:SetAsync(Target.UserId, encodedData)
			end)
			
			if success then
				print("Successfuly ban " ..Target.Name.. " for " ..Day.. "d-" ..Hour.. "h-" ..Min.. "min.")
			else
				print("Something wrong happened while banning " ..Target.Name.. ".")
				warn(err)
			end

			Target:Kick("You are kicked by " ..player.Name.. " for: " ..Length.. ". Reason: " ..Reason)
		else
			player:Kick("You can't ban a admin that has more power than you!")
		end
	end
end)

UnbanEvent.OnServerEvent:Connect(function(player, target)
	local UserId = game.Players:GetUserIdFromNameAsync(target)
	
	BanData:RemoveAsync(UserId)
end)

script.BanEvent.Event:Connect(function(player, Duration)
	local TimeNow = os.time()
	local EndTime = TimeNow + Duration
	
	BanData:SetAsync(player.UserId, EndTime)
end)

I see you’re using an OrderedDataStore, use a normal one with DataStoreService:GetDataStore(“BanData”)

2 Likes

Oh ok thanks ! But I really can’t use the OrderedDataStore to save it ? I would like to have a board with the banned players. Is there any other solutions ?

im having the same problem here. can’t seem to figure it out…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.