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()??

9 comments
http://wiki.roblox.com/index.php?title=Function_dump/Functions_specific_to_ROBLOX#tick Use this in such a way that you call the difference from when the player was banned to when they try and join, or even when the server updates. and check your things there.
Can you please have like an example, because the wiki doesn't do a good job in explaining
I can give one based on the player joining. Give me a second.
You're gonna need to save things across the data store.
Ok, other than that should it work?
How should it be saved?? SaveNumber, SaveString, SaveBoolean??
Mhmm.
Editted, can you check and tell me if it works. I used SetAsync and GetAsync for it
It says that timeBanned is nil...