Script sometimes work, sometimes doesnt

	SpawnPart1 = workspace:WaitForChild("benespawn");
	SpawnPart2 = workspace:WaitForChild("MENUSPAWB");
	SpawnPart3 = workspace:WaitForChild("citizenspawn");
	SpawnPart4 = workspace:WaitForChild("rebelspawn");
	SpawnPart5 = workspace:WaitForChild("cwuspawn");
}
local GroupID = 16221838

game.Players.PlayerAdded:Connect(function(player)
	if player:GetRankInGroup(GroupID) ~= 255 then return end
	player.CharacterAdded:Connect(function(char)
		print("Hey")
		if player.Team.Name == "Combine" and player:GetRankInGroup(GroupID) == 255 then char:PivotTo(spawns[string.format("SpawnPart1", player.Team.Name == "Combine")]:GetPivot() * CFrame.new(0, 2.5, 0))
		elseif player.Team.Name == "Menu" then char:PivotTo(spawns[string.format("SpawnPart2", player.Team.Name == "Menu")]:GetPivot() * CFrame.new(0, 2.5, 0))
			print("GG")
		elseif player.Team.Name == "Citizens" then char:PivotTo(spawns[string.format("SpawnPart3", player.Team.Name == "Citizens")]:GetPivot() * CFrame.new(0, 2.5, 0))
		elseif player.Team.Name == "CWU" then char:PivotTo(spawns[string.format("SpawnPart5", player.Team.Name == "CWU")]:GetPivot() * CFrame.new(0, 2.5, 0))
			print("Ht")
		elseif player.Team.Name == "Rebel" then char:PivotTo(spawns[string.format("SpawnPart4", player.Team.Name == "Rebel")]:GetPivot() * CFrame.new(0, 2.5, 0))
			print("Here")
		end
	end)
end)

this is a script ive made for a group rank team spawn thingy, it used to work, but now it sometimes work, and sometimes doesnt

wat. is there any more details than just “this is a script ive made for a group rank team spawn thingy, it used to work, but now it sometimes work, and sometimes doesnt”

however, my first speculation would be that the player gets loaded faster than the script. add checks to see if players already exist in the game, and if it works there you go

also you don’t need to return end, just do

if player:GetRankInGroup(GroupID) == 255 then 
       //code in here

end

does characteradded and playeradded in the script not do it already?