Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help saving players time while offline?

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

0

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.

0

Can you please have like an example, because the wiki doesn't do a good job in explaining

0

I can give one based on the player joining. Give me a second.

0

You're gonna need to save things across the data store.

0

Ok, other than that should it work?

0

How should it be saved?? SaveNumber, SaveString, SaveBoolean??

0

Mhmm.

0

Editted, can you check and tell me if it works. I used SetAsync and GetAsync for it

0

It says that timeBanned is nil...

1 answer

✓ Accepted answer
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)

10 comments

0

Ok, can you explain time and timeBanned a bit more. With time, does it equal the amount of time they have to wait till they get unbanned? and then what about timeUnbanned

0

Time = time they have to wait to be unbanned. For example your 86400...

0

Ok, then what about timeBanned?? does that just stay 0??

0

timeBanned = the time in Unix time they were banned. The tick(). You need to have this stored for this to work.

0

So would it just equal tick()??

0

No. When you ban the player store tick(). then when the player tried to join, load that stored value..

0

So when they are banned, save tick(), and when they try to rejoin, reload that tick?

0

Mhmm.

0

Hold on, I'll edit my question with what I have got

0

Editted

This discussion is preserved as it was. New answers, comments, and votes are closed.