I have made a script to un ban the player after it meets the ban date and it dont seem to work. can i get help? the code i have is

--//  Variables

--  DataStore

local DS = game:GetService("DataStoreService")
local BanDataStore = DS:GetDataStore("BanDataStoreStudioTest")

--  Other Variables

local RStorage = game.ReplicatedStorage
local BanFunction = RStorage.BanPlayer
local UnBanFunction = RStorage.UnBanPlayer
local AdminIds = {261477936, 1, 156, -1}
local Storage = game.ServerStorage
local BanFolder = Storage.BanFolder

--//  Kick If Ban Date Not Met

game.Players.PlayerAdded:Connect(function(Player)
	
	--  BanLocals
	
	wait(.1)
	local PlayerBanFolder = BanFolder[Player.UserId]
	local BanDate = BanDataStore:GetAsync(Player.UserId)
	local DayLength = PlayerBanFolder.DayLength
	local Reason = PlayerBanFolder.Reason
    if BanDate then
		local Seconds = os.time()-tonumber(BanDate.BanLength)
    	local Minutes = Seconds/60
    	local Hours = Minutes/60
		local Days = Hours/24
        if Days <= DayLength.Value then
            Player:Kick(Reason.Value.." Please Appeal In Our Discord Server In Channel 'assassination-secrecy-appeal' For A Chance To Be Un-Banned Early Or Reduce!")
		elseif Days >= DayLength.Value then
	        PlayerBanFolder.Reason.Value = ""
			PlayerBanFolder.DayLength.Value = 0
	    end
	end
end)

2 comments

2

you can store when they were banned by using tick() and then when they rejoin the game, check the current time (tick()) and subtract the time they were banned. this will give you how long they were banned for

0

thanks royaltoe