Hello, I have a problem where a PlayerRemoving function runs “too late”, and the player’s team is recognized as “nil”, is there any solution to this?
This is currently a part of my code:
( “[REDACTED]” is replaced with a actual webhook, this is just for the sake of this post)
local httpservice = game:GetService("HttpService")
local webhookURL = "[READCTED]"
local Teams = game:GetService("Teams")
game.Players.PlayerRemoving:Connect(function(Player)
local timervar = (Player:FindFirstChild("timer").Value)
print(timervar) -- Testing purposes
local MessageData = {
["content"] = Player.Name .. " | " .. timervar .. " Minutes"
}
MessageData = httpservice:JSONEncode(MessageData)
if Player.Team == Teams.Team2 then
print("hi") -- Also testing purposes
httpservice:PostAsync(webhookURL,MessageData)
end
end)