I have it so when a player is moderated (banned) in the game, it sets a value
in there player to the amount of seconds they have been banned for from my game, but I can't get it to count down. I don't want it to count down in game, cause if they try rejoining they will get kicked straight away. I have it so the seconds is timed by 60*60*24
to convert it to days, so if they are banned for 3 days, then the value would be 86400
I want this to countdown so even if the player isn't online it still counts down. I'm guessing it has something to do with os.time()
but it's really confusing and the wiki doesn't explain it well.
moderationEvent.OnServerEvent:connect(function(player, ...) if player then local tuple = {...} local playerDataFolder = player:WaitForChild("PlayerDataFolder") if tuple[1] == "Banned" then mydata.banned = true playerDataFolder.Banned.Value = mydata.banned mydata.bannedtime = tuple[2]*60*60*24 playerDataFolder.Banned.BannedTime.Value = mydata.bannedtime -- I believe the countdown should go here -- end end end)
Do not worry that I didn't show what the event, playerdata, etc. are. That is not important here and there are no bugs. It's just trying to count down the time while the players gone. So basically I want the BannedTime.Value
to count down while the player is not on the server.
Any help is appreciated.
EDIT
game.Players.PlayerAdded:connect(function(player) local banned = Instance.new("BoolValue", playerDataFolder) banned.Name = "Banned" banned.Value = mydata.banned local bannedTime = Instance.new("IntValue", banned) bannedTime.Name = "BannedTime" bannedTime.Value = mydata.bannedtime local time = bannedTime.Value local timeBanned = moderationData:GetAsync(player.userId) local currentTick = tick() if (currentTick-timeBanned)>= time then --unban the player end end) moderationEvent.OnServerEvent:connect(function(player, ...) if player then local tuple = {...} local playerDataFolder = player:WaitForChild("PlayerDataFolder") if tuple[1] == "Banned" then mydata.banned = true playerDataFolder.Banned.Value = mydata.banned mydata.bannedtime = tuple[2]*60*60*24 playerDataFolder.Banned.BannedTime.Value = mydata.bannedtime moderationData:GetAsync(player.userId) end end end)
Is this it? Or should I have a datastore that stores the tick()??
game.Players.PlayerAdded:connect(function(plr) local time = 0 --get the total time the player was banned from somewhere. local timeBanned = 0 --get the tick() the player was banned, you need to save this when the player gets banned local currentTick = tick() if (currentTick-timeBanned)>= time then --unban the player end end)