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

How to track time warned in my warn system?

Asked by 4 years ago

Hi,

In my game there's a warn system, and after 9 hours the warn goes away. I've already got it that a folder called 'Warns' appears in a player every time they join, and there are subfolders with the following values: The admin that warned them, the warn reason and the warn ID.

I need help with the wearing off bit, so that 9 hours later the warn gets deleted.

I've been looking for answers but nothing helped much.

0
You could use os.time() to record the time in seconds. FunctionalMetatable 490 — 4y
0
or tick() Leamir 3138 — 4y

1 answer

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

This is not a request site, but I'll help.

Make sure this is a script, not a local script. If your warning system is a GUI, you can fire a remote event to this script. More information here.


local DataStoreService = game:GetService("DataStoreService") local warnsystem = DataStoreService:GetDataStore("warnsystem") game.Players.PlayerAdded:connect(function(plr) local system = Instance.new("Folder") -- making folder system.Name = system -- naming it system system.Parent = plr -- putting it inside of the player local secondsuntilunwarn = Instance.new("NumberValue") -- making a numbervalue secondsuntilunwarn.Name = secondsuntilunwarn -- naming it secondsuntilunwarn secondsuntilunwarn.Value = warnsystem:GetAsync(player.UserID) or 0 -- putting the value to the saved data or 0 if they have no data secondsuntilunwarn.Changed:Connect(function() -- if it changes warnsystem:SetAsync(player.UserID, secondsuntilunwarn.Value) -- save it end ) end ) --RemoteEvent (client to server) game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)-- make sure its located in replicated storage and you fired it from the client local target = os.time() + 32400 -- os.time + 9 hours in seconds -- local function toHMS(s) --convert to hours, minutes, seconds, and format to 0 left-padded integers separated by colons. return ("i:i:i"):format(s / 3600, s / 60 % 60, s % 60) -- returning the format end plr.system.secondsuntilunwarn.Value = os.time() -- when the player is warn the secondsuntilwarn value becomes the os.time of that time local HMS_Until_Unwarn = (toHMS(target - plr.system.secondsuntilunwarn.Value)) -- hours, minute seconds until unwarn end )

What is os.time? os.time returns how many seconds have passed since the Unix epoch (1 January 1970, 00:00:00), under current UTC time. If provided a table formatted similarly to that returned by os.date, it will return the number of seconds since that time instead.

How can I fire client to server using remote events?

local RemoteEvent = game.ReplicatedStorage.RemoteEvent

RemoteEvent:FireServer(data) -- if you're doing this in the warning system makes the data /parameter player
Ad

Answer this question