I am trying to make an auto team script, but GetRankInGroup is not working, or maybe team setting, but that is unlikely. Anybody who can, at least, tell me which is the problem, will be helpful.

local player = game.Players.LocalPlayer.UserId
local actualplayer = game.Players.LocalPlayer
local teams = game.Teams
local groupid = 8530777

game.Players.PlayerAdded:Connect(function(player)
	if player:IsInGroup(groupid) and player:GetRankInGroup(groupid) >= 3 then
		actualplayer.Team = teams["The Foundation"]
	else
		actualplayer.Team = teams.Loners
	end
end)