Hello, my name is Pixel, and today I am asking for some serious help regarding an offline banning system for my Roblox game. I just wanted to ask if anyone has an idea on how that would be possible. Thank you.
os.time() returns an Integer of how many seconds have passed since 1 January 1970. You could use os.time() and adding timed bans onto os.time() and saving it into a datastore.
Said datastore could then be loaded into the game upon the player’s joining and kick the player if it detects that os.time() is less than the time saved in the datastore.
Some code would look like this;
The script which loads upon the player’s joining;
game.Players.PlayerAdded:Connect(function(Player)
local BannedData
local Success, Error = pcall(function()
BannedData = BannedPlayers:GetAsync(Player.UserId)
end)
if BannedData and Success == true then
if BannedData[1] > os.time() then
local function CalculateDaysLeft(DataToLook)
local TimeOfUnban = DataToLook[1]
local TimeOfBan = DataToLook[3]
local Difference = TimeOfUnban - TimeOfBan
local Result = Difference / 86400
return tostring(Result)
end
Player:Kick("\nYou have been deported from the Holy Islands. \n\nReason: "..tostring(BannedData[2]).."\n You are banned for "..CalculateDaysLeft(BannedData).." more day(s).")
end
end
print(BannedData)
end
The script that sets the ban in the datastore
--[[
BannedData[1] = os.time() + (86400 x Y amount of days) <- Unban time
BannedData[2] = Reason
BannedData[3] = os.time() <- Time of ban
--]]
local BannedData = {os.time() + Info[3], Info[2], os.time()}
local Success, Error = pcall(function()
BannedPlayers:SetAsync(Info[1], BannedData)
end)
It’s alot simpler than you’d think!
You have been deported from the Holy Islands.
Is this a free model?
No, it’s from a game I worked on. And if it was, why would it matter? the purpose is to teach this person how to ban people…
how to make unban script? bc im soon want do unban.
I anyway tweaked the script a bit.
game.Players.PlayerAdded:Connect(function(Player)
local BannedData
local BannedPlayers = game:GetService("DataStoreService"):GetDataStore("BannedPlayers")
local Success, Error = pcall(function()
BannedData = BannedPlayers:GetAsync(Player.UserId)
end)
if BannedData and Success == true then
if BannedData[1] > os.time() then
local function CalculateDaysLeft(DataToLook)
local TimeOfUnban = DataToLook[1]
local TimeOfBan = DataToLook[3]
local Difference = TimeOfUnban - TimeOfBan
local Result = Difference / 86400
return tostring(Result)
end
Player:Kick("\nYou have been deported from the Holy Islands. \n\nReason: "..tostring(BannedData[2]).."\n You are banned for "..CalculateDaysLeft(BannedData).." more day(s).")
end
end
end)
BannedPlayers:RemoveAsync(userid)
Where? I’m looking at the script and I can’t really see any changes.