EDIT: Sorry for my bad explanation. I want to count the amount of time the player been playing for. when the player leaves the server it calculates the time duration then sends a log to my discord server.
This is my attempt. It only works for one person for some reason Let's say there's two players on a server, when the first leaves it works fine, but for the second it doesn't.
local webhook = "" local http = game:GetService('HttpService') local Embed_Colors = { 0xFF0000, 0xFF7F00, 0xFFFF00, 0x00FF00, 0x0000FF, 0x8B00FF } function get_ebic_date(t) local date_table = os.date("!*t", t) local year, month, day, hour, min, sec = date_table.year, date_table.month, date_table.day, date_table.hour, date_table.min, date_table.sec local period = "AM" if hour >= 12 then period = "PM" hour = hour ~= 12 and hour - 12 or hour end local last_date = string.format("%d-%d-%d", year, month, day) .. " UTC" .. "\n" .. string.format("%.2d:%.2d:%.2d %s", hour, min, sec, period) return last_date end function get_ebic_time(thetime) local timefloor = math.floor(thetime) local hours = math.floor(thetime / 3600) local mins = math.floor(thetime / 60) local secs = math.floor(thetime % 60) local hour_form = hours < 10 and "0" .. hours or hours local min_form = mins < 10 and "0" .. mins or mins local sec_form = secs < 10 and "0" .. secs or secs local readytime = hour_form .. " hours, " .. min_form .. " minutes, and " .. sec_form .. " seconds." return readytime end function embed(player, timing) local data = { ["avatar_url"] = "https://t6.rbxcdn.com/e92158c999f48841ac15d66adc6502c8", ["username"] = "Cannonial Activity System", ["embeds"] = {{ ["color"] = Embed_Colors[math.random(1,#Embed_Colors)], ["title"] = "Profile Link", ["url"] = "https://www.roblox.com/users/" .. player.UserId .. "/profile", fields = { {name = "Name", value = player.Name, inline = true}, {name = "Rank", value = tostring(player:GetRoleInGroup(3405614)), inline = true}, {name = "Time Spent", value = timing}, {name = "Date Assigned", value = get_ebic_date()} }, }} } return data end function send(player, timing) local json = http:JSONEncode(embed(player, timing)) http:PostAsync(webhook, json, Enum.HttpContentType.ApplicationJson) end local staff = {} function duration(player) if player:GetRankInGroup(3405614) >= 50 then staff[player] = os.time() end end function count_end(player, now) if player:GetRankInGroup(3405614) >= 50 then now = get_ebic_time(os.time() - staff[player]) send(player, now) end end game.Players.PlayerAdded:connect(duration) game.Players.PlayerRemoving:connect(count_end)