There are probably things for this but I want to know how you do it, that way you dont just look up a tutorial and guess if it works, I need to make sure its not outdated ya know ya know.
Any ways thanks!
There are probably things for this but I want to know how you do it, that way you dont just look up a tutorial and guess if it works, I need to make sure its not outdated ya know ya know.
Any ways thanks!
Datastores
are pretty much the only way. Whenever you want to ban someone, just give them a special tag in a store, then kick them.
You can check for that tag on join and just kick them whenever they try to join.
Here’s an example from my own admin tools script that I made a bit ago:
function CheckForBan(Player: Player)
local CurrentTime = os.time()
local BanInfo = NovaAdminBans:GetAsync(Player.UserId)
if BanInfo then
if AdminList:RetrieveAdminLevel(Player.UserId) >= 3 then
print("Banned admin; backpedaling.")
NovaAdminBans:SetAsync(Player.UserId, {["BanUntil"] = "null", ["BanType"] = "null"})
end
if BanInfo.BanUntil > CurrentTime and BanInfo.BanType == "Temp" then
local DateTable = GetReadableTimeFromUnix(BanInfo.BanUntil - CurrentTime)
Player:Kick("You have been temporarily banned. Time until Unban: ["..DateTable.Days.." days, "..DateTable.Hours.." hours, "..DateTable.Minutes.." minutes, "..DateTable.Seconds.." seconds.]")
end
if BanInfo.BanType == "Perm" then
Player:Kick("You have been permanently banned.")
end
end
end
PlayerService.PlayerAdded:Connect(CheckForBan)
What is this? Is this a custom function you made? Cause its not a thing for me.
Also thanks! Almost finished writing this whole thing out and testing it! Thanks again!
Now I know how to save the datastore and ban a user(Thanks btw) but how do I get the time to ban them for? Lets say I wanted to ban them for a day, how would I take the current time and add 1 day?
Also thanks!
You’d save the time (os.time) they were banned in the datastore and when they join (Players.PlayerAdded), you just subtract the saved value by os.time.
Let’s say you banned them and os.time is 6 hours (ITS A SMALL NUMBER TO MAKE IT EASY).
You wanna ban them for 6 more hours. When they rejoin 4 hours later (os.time = 10 hours), you subtract os.time by the saved value and find out that they have to wait 2 more hours.
And finally they wait 2 hours and you check if the saved value subtracted by os.time is = 0 (it’s been 6 hours) or is less than 0 (which means it’s been more than 6 hours).
This entire post is explaining this basically
Just wondering, but if I banned them for a whole week, if I did os.time wouldnt that return just the time and not the date right? cause if they join the next day at the exact time they got banned, os.time would be the same therefore they would be unbanned, unless os.time includes the date they got banned and the time
function GetReadableTimeFromUnix(UnixTime: number)
local DateTable = {
Days = math.floor(UnixTime/86400),
Hours = math.floor(UnixTime/3600) % 24,
Minutes = math.floor(UnixTime/60) % 60,
Seconds = UnixTime % 60
}
return DateTable
end
This is just so that you can read how much time you have left until you are unbanned.
Easy. I just use os.time()
It gives you the current unix time, which is just a count of seconds since Jan 1st 1970.
Since we are dealing with seconds, if you want to ban someone for a day you would just do:
60 Minutes * 60 Minutes * 24 Hours (86,400)
Then I add that to the os.time()
from earlier and save it in the datastore. (So what we basically did was just (os.time() + 86400).
Just subtract the time it is for the person when they join from the server.
os.time() - Time we calculated earlier
And if its 0 or less, then they can safely join.
OR you could just do
if os.time() >= TimeUntilUnban then Unban() end
Whoops. I guess simplifying it made it confusing.
os.time
returns the time since the Unix Epoch (January 1, 1970 00:00:00 Universal TS). So basically it doesn’t reset every new day.
oh ok this makes much more senes! Thank you!
Just a quick question, what do I set the BanUntil value to? A number or a time? From the look of things I am going to assume a number but I wanted to make sure yk yk
It’s going to be the unix time that they get unbanned on. So, os.time() + SecondsUntilUnban
well roblox has a ban API now so ima just use that lol
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.