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

Help saving players time while offline?

Asked by 8 years ago

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

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. TinyPanda273 110 — 8y
0
Can you please have like an example, because the wiki doesn't do a good job in explaining NinjoOnline 1146 — 8y
0
I can give one based on the player joining. Give me a second. TinyPanda273 110 — 8y
0
You're gonna need to save things across the data store. TinyPanda273 110 — 8y
View all comments (5 more)
0
Ok, other than that should it work? NinjoOnline 1146 — 8y
0
How should it be saved?? SaveNumber, SaveString, SaveBoolean?? NinjoOnline 1146 — 8y
0
Mhmm. TinyPanda273 110 — 8y
0
Editted, can you check and tell me if it works. I used SetAsync and GetAsync for it NinjoOnline 1146 — 8y
0
It says that timeBanned is nil... NinjoOnline 1146 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
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)
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 NinjoOnline 1146 — 8y
0
Time = time they have to wait to be unbanned. For example your 86400... TinyPanda273 110 — 8y
0
Ok, then what about timeBanned?? does that just stay 0?? NinjoOnline 1146 — 8y
0
timeBanned = the time in Unix time they were banned. The tick(). You need to have this stored for this to work. TinyPanda273 110 — 8y
View all comments (6 more)
0
So would it just equal tick()?? NinjoOnline 1146 — 8y
0
No. When you ban the player store tick(). then when the player tried to join, load that stored value.. TinyPanda273 110 — 8y
0
So when they are banned, save tick(), and when they try to rejoin, reload that tick? NinjoOnline 1146 — 8y
0
Mhmm. TinyPanda273 110 — 8y
0
Hold on, I'll edit my question with what I have got NinjoOnline 1146 — 8y
0
Editted NinjoOnline 1146 — 8y
Ad

Answer this question