Issues with datastore saving?

Attempting to make a ban module for moderation in my games, using datastore but it doesn’t appear to save.

I’m attempting to save a table with the info on the ban, like the reason, and the duration of said ban.

I know I’ve probably overlooked something obvious.

The ModuleScript :

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local BanDS = DataStoreService:GetDataStore("SingularityBans")

local BanModule = {}

function BanModule.BanPlayer(UserID:number, Reason:string, isTemporary:boolean, BanDuration:number)
	local success, err = pcall(function()
		local BanEndDate = (os.time() + BanDuration*86400) or 1
		
		BanDS:SetAsync("USER_"..tostring(UserID), {BanReason = Reason, IsBanned = true, BanEndTime = BanEndDate})
	end)
	
	local Plr = Players:GetPlayerByUserId(UserID)
	Plr:Kick(Reason)
	
	if not success then
		warn("Failed to ban player:", err)
	end
end

Players.PlayerAdded:Connect(function(Plr:Player)
	local UserID = Plr.UserId
	local success, result = pcall(function()
		return BanDS:GetAsync("USER_"..tostring(UserID))
	end)

	if success and result then
		if result.IsBanned and (result.BanEndTime == 0 or result.BanEndTime > os.time()) then
			Plr:Kick(result.BanReason)
		end
	end
end)

return BanModule
2 Likes

try turning the table into a string. i don’t think datastores like tables that much, though i could be wrong.

try

local information = HttpService:JSONEncode{BanReason = Reason, IsBanned = true, BanEndTime = BanEndDate}
BanDS:SetAsync("USER_"..tostring(UserID), information)
	end)
	local success, result = pcall(function()
		return HttpService:JSONDecode(BanDS:GetAsync("USER_"..tostring(UserID)))
	end)

you might have to change a few things up. i forget whether or not JSON is fully capitalized

1 Like

Still doesn’t appear to be working. It kicks the player still, but when they rejoin they aren’t kicked.

Video :

This is wrong, you’re perfectly allowed to store tables and dictionaries in DataStoreService.

@JaydenTheProtogen
Can you show me the errors that happen?

Sorry about the delayed response, there aren’t any errors in output or console.