Thank you so much! I wish everyone was like you.
I guess you could somehow check the Epoch time and if the epoch time is > than the value of when you banned the person then they are no longer banned.
Nearly done. Just need to set up the command or can you do that?
Wait can’t they change their OS’s time? Meaning they can just change their devices time in the settings to get un-temp banned.
I’m fine with the command lol, I don’t want you to script everything.
Basically. You would create a timestamp for when they were banned, add it to their datastore, and every time they try to rejoin you check if they have a ban timestamp or whatever and do some math (timestamp - current time) to check the difference between when they were banned and when they’re rejoining the game. If enough time hasn’t passed, kick them. Otherwise, remove the timestamp and let them play.
The problem is that I don’t know how to script it…
I am done in 1 minute. I will teach you how I did it after.
not really. iirc, os.time() returns the amount of seconds since the epoch (January 1st 1970 00:00:00). It isn’t the date that’s set on the computer.
os | Roblox Creator Documentation (oh hey look, there’s a dedicated function os.difftime for checking difference between two times)
This is pretty much all you need.
Its jan 1st not 7th okkkkkkkkkk
Isn’t that tick()
? Ok never mind
I am done. Try this out I also gave you a function to ban player.
local globaldatastore = game:GetService("DataStoreService")
local bans = globaldatastore:GetDataStore("TempBans")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
local banData
local good, bad = pcall(function()
banData = bans:GetAsync("plr_"..tostring(player.UserId))
end)
if bad then
warn("Error getting datastore: "..bad)
end
if banData ~= {} then
local prevtime = banData[1]
local reason = banData[2]
local banlength = banData[3]
if os.time() < (prevtime+banlength) then
local timeleft = (prevtime+banlength)-os.time()
local hours = math.floor(timeleft/3600)
local hs = timeleft % 3600
local mins = math.floor(hs/60)
local secsleft = hs%60
player:Kick(reason.. " for: "..hours.." Hours, "..mins.." Mins, "..math.floor(secsleft).. " Seconds")
else
local g,b = pcall(function()
bans:SetAsync("plr_"..tostring(player.UserId),{})
end)
if g then
print("player waited their time and got unbanned succesfully.")
else
warn("error setting datastore: ".. b)
bans:SetAsync("plr_"..tostring(player.UserId),{})
end
end
end
end)
function BanPlayer(userid,timeinseconds,reason)
if game.Players:GetPlayerByUserId(userid) then
local timeleft = timeinseconds
local hours = math.floor(timeleft/3600)
local hs = timeleft % 3600
local mins = math.floor(hs/60)
local secsleft = hs%60
game.Players:GetPlayerByUserId(userid):Kick(reason.. " for: "..hours.." Hours, "..mins.." Mins, "..math.floor(secsleft).. " Seconds")
local g,b = pcall(function()
bans:SetAsync("plr_"..tostring(userid),{os.time(),reason,timeinseconds})
end)
if g then
print("succesfully banned player.")
else
warn("error setting ban datastore: "..b)
bans:SetAsync("plr_"..tostring(userid),{os.time(),reason,timeinseconds}) -- attempt agian.
end
else
local g,b = pcall(function()
bans:SetAsync("plr_"..tostring(userid),{os.time(),reason,timeinseconds})
end)
if g then
print("succesfully banned player.")
else
warn("error setting ban datastore: "..b)
bans:SetAsync("plr_"..tostring(userid),{os.time(),reason,timeinseconds}) -- attempt agian.
end
end
end
Thanks. I’ve the updated post.
I am not sure if that will work or not, we could try it out in a test place?
tick() is deprecated and less precise. Should not be used for new work.
How could I place your script in this:
local moderation = {}
local BanDDS = game:GetService("DataStoreService"):GetDataStore("ban-key-A54")
local TempBanDDS = game:GetService("DataStoreService"):GetDataStore("tempban-key-B64")
function moderation:PlrKick(plr, reason)
local plr = game:GetService("Players"):FindFirstChild(plr)
if plr then
if reason ~= nil or reason ~= "" then
plr:Kick(reason)
else
plr:Kick("You have been kicked from the game, no reasons where specified.")
end
end
end
function moderation:ShadowBan(plr)
local plr = game:GetService("Players"):FindFirstChild(plr)
BanDDS:SetAsync(plr.UserId.."-SBAN",true)
if plr then
local char = workspace:WaitForChild(plr.Name)
char.Humanoid.WalkSpeed = 0.012 and char.Humanoid.JumpPower == 0.012
local darkframe = Instance.new("ScreenGui")
darkframe.Parent = plr.PlayerGui
darkframe.Name = "ShadowBan"
local main = Instance.new("Frame")
main.Name = "main"
main.Parent = darkframe
main.BackgroundColor3 = Color3.new(0,0,0)
main.BorderColor3 = Color3.new(0,0,0)
main.Size = UDim2.new(1,0,1,0)
main.BackgroundTransparency = UDim.new(0.5)
darkframe.IgnoreGuiInset = true
darkframe.ResetOnSpawn = false
darkframe.Archivable = false
task.wait(10)
plr:Kick("Error\nInternal Server Error (500)\nAn unexpected error occured")
end
end
function moderation:PermBan(plr, reason)
local plr = game:GetService("Players"):FindFirstChild(plr)
BanDDS:SetAsync(plr.UserId.."-PBAN",true)
if reason ~= nil or reason ~= "" then
plr:Kick("[PERM BAN]\nYou have been permanently banned.\nReason: "..reason)
else
BanDDS:SetAsync(plr.UserId.."-PBAN",true)
plr:Kick("[PERM BAN]\nYou have been permanently banned.")
end
end
function moderation:ServerBan(plr, reason)
local plr = game:GetService("Players"):FindFirstChild(plr)
BanDDS:SetAsync(plr.UserId.."-SERVBAN",true)
if reason ~= nil or reason ~= "" then
plr:Kick("[SERVER BAN]\nYou have been banned from this server.\nReason: "..reason)
else
BanDDS:SetAsync(plr.UserId.."-SERVBAN",true)
plr:Kick("[SERVER BAN]\nYou have been banned from this server.")
end
end
function moderation:RevokeBan(plr)
local plr = game:GetService("Players"):FindFirstChild(plr)
if BanDDS:GetAsync(plr.UserId.."-PBAN",true) then
BanDDS:SetAsync(plr.UserId.."-PBAN",false)
elseif BanDDS:GetAsync(plr.UserId.."-SERVBAN",true) then
BanDDS:SetAsync(plr.UserId.."-SERVBAN",false)
elseif BanDDS:GetAsync(plr.UserId.."-SBAN",true) then
BanDDS:SetAsync(plr.UserId.."-SBAN",false)
elseif BanDDS:GetAsync(plr.UserId.."-TBAN",true) then
BanDDS:SetAsync(plr.UserId.."-TBAN",false)
end
end
game.Players.PlayerAdded:Connect(function(plr)
if BanDDS:GetAsync(plr.UserId.."-PBAN",true) then
plr:Kick("[PERM BAN]\nYou are currently permanently banned.")
elseif BanDDS:GetAsync(plr.UserId.."-SBAN",true) then
moderation:ShadowBan(plr.Name)
end
end)
game:BindToClose(function()
local plr = game:GetService("Players")
if BanDDS:GetAsync(plr.UserId.."-SERVBAN",true) then
BanDDS:SetAsync(plr.UserId.."-SERVBAN",false)
end
end)
return moderation
Like a new function, moderation:TempBan() then just link the already put in function side the other function.
Please don’t give people entire scripts like this. Instead, teach them how to do it. You can include a code sample if you want, but you should explain what your code is doing.
See some quote about fish.