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