PlayerRemoving function not being able to get team

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)
1 Like

Maybe try make a variable for the players team at the start of the function? If that doesen’t work then you could probably make a Module Script that has every player in it and their representive team that updates when they change/leave teams.

1 Like

Probably should do that, thanks

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.