Is that intentional? There’s no 0th user on Roblox, so there’d be no thumbnail to fetch for them. Check how you’re fetching the UserId again. Checking the thumbnail link would’ve also helped you to pinpoint a potential problem.
Going to need to see more code if you’re looking for help. The very part that’s problematic has been omitted from your code sample: the only thing you’re sharing is your webhook structure and the use of GetUserThumbnailAsync. These parts are correct, but whatever you’re doing to get the UserId doesn’t seem to be in that same correctness boat.
local Added = script.Parent.Added
local Id = script.Parent.Id
local Name = script.Parent.name
game.Players.PlayerAdded:Connect(function(player)
local added = tick()
Added.Value = added
Id = player.UserId
Name = player.Name
end)
That’s why you should do some review of your own code and debugging before posting threads! If you did a quick review, you might’ve caught the problem. You’re just redefining a variable rather than actually assigning any values.
local Added = script.Parent.Added
local Id = script.Parent.Id
local Name = script.Parent.name
game.Players.PlayerAdded:Connect(function(player)
local added = tick()
Added.Value = added
Id.Value = player.UserId
Name = player.Name
end)
You posted your whole code sample while I was replying so I had to change my wording a bit. Anyhow.
Your id is still 0 because you have another oversight which is the way you define the id. PlayerAdded may not have fired before setting Id.Value, so by the time Id.Value is indexed for the GetUserThumbnailAsync call it’s still 0. You could simply fix this by moving the GetUserThumbnailAsync call into PlayerRemoving instead.
You should probably reconsider the way you’re creating this system, like not using a ValueObject here and instead going for a dictionary and putting everything in one script instead. Would be much easier and not weird to maintain.
When the player joins, log when they joined and add them to a dictionary.
When the player leaves, get their time. Do some calculations to find out how much they spent in the game, then send that in your webhook.
Roughly:
local Players = game:GetService("Players")
local playerJoinTimes = {}
local function playerAdded(player)
local timeNow = DateTime.now() -- You can also just use os.time()
playerJoinTimes[player.UserId] = timeNow
end
local function playerRemoving(player)
local joinTime = playerJoinTimes[player]
-- If they were not tracked, do nothing
if not joinTime then return end
local timeNow = DateTime.now()
local timeInGame = timeNow.UnixTimestamp - joinTime.UnixTimestamp
-- Do some math with timeInGame to find out how long they've played.
-- timeInGame will be in seconds; up to you to convert to minutes/hours.
-- You can also use this to send via the webhook.
end
Players.PlayerAdded:Connect(playerAdded)
Players.PlayerRemoving:Connect(playerRemoving)
for _, player in ipairs(Players:GetPlayers()) do
playerAdded(player)
end