Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How would I make a good ban system for banning players?

Asked by 6 years ago
Edited 6 years ago

I just wanna know how you could ban a player for a few days not allowing them to join back until their time is up.

I know i am gonna have to use DataStores. I just want tips not code

2 answers

Log in to vote
4
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Yes, you'll have to use DataStores, but there are other ways of saving data.

You'll have to create your datastore first by doing, and initiate an array for people who have been banned by doing:

local bans = game:GetService('DataStoreService'):GetDataStore('Bans')
local banned = bans:GetAsync('gameBans') or {} --If there's no data saved, we create a blank table. 'gameBans' is just a random key for the banlist

If you want to add a player to a banlist, you can use table.insert or another method I'm gonna show. Then, you're going to kick the player save the table.

-- Example below
banned[#banned + 1] = {
         Name = player.Name; -- let's way we've specified 'player' to game.Players.Player1
         Time = tick()+86400 -- The current time in the next day
}
player:Kick("You're banned hehe")
bans:SetAsync('gameBans', banned) -- Saving to the random key we've created

When a player joins, you'll have to check if the player is on the banlist. If they are, and their time hasn't reached the time the player's been banned for, we kick the player from the game

game.Players.ChildAdded:Connect(function(player)
        for i,v in pairs(banned) do
               if v.Name == player.Name and tick() < v.Time then
                      player:Kick('Kicking the player because they're time isn't Up')
               elseif v.Name == player.Name and tick() >= v.Time then
                       table.remove(banned, i) --removing the player's ban
                       bans:SetAsync('gameBans', banned) --Updating the banlist
               end
        end
end)

Hope this helped

Ad
Log in to vote
1
Answered by 6 years ago

for 1 i would use os.time for tracking their start of ban, another for getting the end of ban

86400 seconds in a day

set the table stored in datastore to nil after its done

local daysforban = 30
local baninfo = {
    start = os.time()
    end = daysforban*86400
}

thats really all i can say

0
Remember, end is already a syntax in Roblox Lua, change it to End or to [“end”] saSlol2436 716 — 6y

Answer this question