I’m trying to make an activity tracker script for a ROBLOX group that is linked to a webhook, which puts out this message:
As you can see here, it works for 0 minutes, but my problem is making it work for any value above 0 after waiting for 60 seconds. I’ve put my code down below:
local Webhook = "" -- Webhook was removed for privacy reasons
local HttpService = game:GetService("HttpService")
local GroupId = 6101649
local MinRank = 13
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(GroupId) >= MinRank then
local Timer = Instance.new("NumberValue",Player) Timer.Name = "PlayTime"
while wait(60) do
Timer.Value += 1
end
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
if Player:GetRankInGroup(GroupId) >= MinRank then
local payload = HttpService:JSONEncode({
content = "<:konditori:817494014215323698> **NEW ACTIVITY LOG** \n **Username:** "..Player.Name.." \n **Rank:** "..Player:GetRoleInGroup(GroupId).." \n **Game:** Konditori Bakery \n **Time:** " ..Player.PlayTime.Value.." minute(s)",
username = "Activity Logger"
})
HttpService:PostAsync(Webhook, payload)
end
end)
After a minute passes and someone leaves the game (in this case, me), the webhook is no longer fired. I’ve tested the wait to add to the timer with 5 seconds instead of 60 seconds, and that worked, but 60 seconds doesn’t seem to work. I’ve tried to change 60 into 30 * 2 and 10 * 6, but those don’t seem to be working either.
If you have any solutions to this, it would be greatly appreciated.
I want the playtime value to go up every minute, and if the player is the appropriate rank and the player leaves the game, the 0 in the Discord message changes to the playtime value. This works for the values underneath a minute, and it comes out as 0 minutes. Once it changes to over a minute, it stops working.
You can get the time the player joined and then use the difference of time when they leave:
local PlayerJoinedTable = {}
Players.PlayerAdded:Connect(function(Player)
PlayerJoinedTable[Player].JoinTime = os.time() -- os.time() because it's recorded every second, os.clock() is more accurate but we want seconds
end)
Players.PlayerRemoved:Connect(function(Player)
local ElapsedTime = os.time() - PlayerJoinedTable[Player].JoinTime -- Getting the amount of time spent in the server
PlayerJoinedTable[Player] = nil -- Setting to nil so it doesn't allocate memory
end)